DEV Community

Cover image for React Hooks in 5 Minutes

React Hooks in 5 Minutes

Jhey Tompkins on January 05, 2020

What are they? A set of functions that provide a direct API to methods we access on Component instances. We can create stateful componen...
Collapse
 
ptejada profile image
Pablo Tejada

Why do you pass the setters to the second param of the useEffect()?

Collapse
 
jh3y profile image
Jhey Tompkins

Good spot Pablo! In that case, it's not necessary and they could be omitted 👍
The docs almost discourage using an empty Array for the optional dependencies list and eslint-plugin-react-hooks's exhaustive-deps rule will in most cases pipe up when using useEffect. That's because in most cases, our effect uses props + state from the component scope. There's a good piece on using the empty Array and why better solutions are normally the way to go here 👍

Collapse
 
ptejada profile image
Pablo Tejada

I think using an empty array looks cleaner and more readable.

Thread Thread
 
jh3y profile image
Jhey Tompkins

Yeah, definitely 👍 But it seems to be discouraged if the effect in question makes use of props + state in the component's scope.

Collapse
 
moatazabdalmageed profile image
Moataz Mohammady

Thanks

Collapse
 
jh3y profile image
Jhey Tompkins

No problem Moataz! 😊

Collapse
 
hermetheus profile image
Allan

Good article thanks!

Collapse
 
jh3y profile image
Jhey Tompkins

Thanks Allan! 😊