Which of the following are true regarding the useEffect hook ? code example
Example 1: react useeffect
import React, { useEffect } from 'react';
const [data,setData]=useState()
useEffect(() => {
fetch(`put your url/api request in here`)
.then(res=>res.json())
.then(json => setData(json))
},[])
Example 2: componentwillunmount hooks
useEffect(() => {
window.addEventListener('mousemove', () => {});
return () => {
window.removeEventListener('mousemove', () => {})
}
}, [])
Example 3: React Hook "useEffect" is called in function
React component names need to start with a capital letter.
That's because React treats components starting with lowercase letters as DOM tags.
Therefore you should name it "Shoes"