Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
32
rated 0 times [  34] [ 2]  / answers: 1 / hits: 18544  / 4 Years ago, mon, march 23, 2020, 12:00:00

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;

More From » reactjs

 Answers
73

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.


[#51110] Friday, March 13, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cristopherh

Total Points: 402
Total Questions: 117
Total Answers: 84

Location: Monaco
Member since Fri, Sep 24, 2021
3 Years ago
;