I'm getting the following error:
React Hook "useEffect" is called in function "shoes" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks
I'm not sure exactly what is the error in my code:
import React, {useState, useEffect} from 'react';
import "../App.css"
function shoes() {
useEffect(() => {
fetchItems();
}, []);
const fetchItems = async () => {
const data = await fetch('xxxxxxxxxxxxxxxxxxxxx')
console.log(data)
};
return ( < h1 className = "main" > Shoes < /h1> );
}
}
export default shoes;
React Hook 'useState' is called in function that is neither a React function component nor a custom React Hook function.
The useEffect Hook allows you to perform side effects in your components. Some examples of side effects are: fetching data, directly updating the DOM, and timers. useEffect accepts two arguments.
The useEffect Hook is called every time the component renders. It works similarly to componentDidMount and componentDidUpdate in React class components.
useEffect() is for side-effects. A functional React component uses props and/or state to calculate the output. If the functional component makes calculations that don't target the output value, then these calculations are named side-effects.
As described here, React component names need to start with a capital letter.
That's because React treats components starting with a lowercase letter as DOM tags.
Therefore you should name it Shoes
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With