bradtraversy / proshop_mern

Shopping cart built with MERN & Redux
2k stars 1.18k forks source link

compilation warning with frontend #200

Closed lily0125 closed 1 year ago

lily0125 commented 2 years ago

When run npm run build for frontend, I got following errors:
Compiled with warnings.

./src/screens/ProductScreen.js Line 44:6: React Hook useEffect has a missing dependency: 'product._id'. Either include it or remove the dependency array react-hooks/exhaustive-deps

./src/screens/OrderScreen.js Line 77:6: React Hook useEffect has missing dependencies: 'history' and 'userInfo'. Either include them or remove the dependency array react-hooks/exhaustive-deps how to fix that ?

Kartikeya-Jain commented 2 years ago

history does not work anymore its useNavigate now!

Smokeengine commented 1 year ago

The most obvious solution to the error would be to add the obj variable to the dependencies array of the useEffect hook. const [address, setAddress] = useState({country: '', city: ''});

// 👇️ objects/arrays are different on re-renders const obj = {country: 'Chile', city: 'Santiago'};

useEffect(() => { setAddress(obj); console.log('useEffect called');

Country: {address.country}

City: {address.city}