I am developing a React app and I don’t know how to solve this error. I’m pretty sure it’s from my useEffect function, but I can’t figure out what’s wrong. Any help would be much appreciated, thank you!
JavaScript
x
16
16
1
const CourseTypeFour = ({ data, classes, bgWhite }) => {
2
let { id } = data;
3
const [courseObject, setCourseObject] = useState({});
4
5
useEffect(() => {
6
axios.get(`http://localhost:3001/courses/${id}`).then((response) => {
7
setCourseObject(response.data);
8
});
9
},[id]);
10
11
return (
12
13
)
14
}
15
export default CourseTypeFour;
16
Advertisement
Answer
The problem isn’t in this part of the code. In error, you can see that problem is when you try to use the toString
method on a variable that is undefined
. Try to find part of the code where you use the toString
method, and before it execute the console.log
function with this variable to see what is inside.