12/12/2020
🤯 React's useEffect( ) is more powerful than I thought.
Many react developers got a taste of "hooks" last year and ever since, it has been hard to go back to class components. I mean, who wants those life cycle methods.. yukkk 😪
The very first hook that we learnt was obviously "useState ( )" which allowed us to maintain an internal state for a given react function component.
👨💻 const [ state, setState ] = useState(initialValue);
We loved ❤️ the performance it brought as redux state updates are comparatively slower. When I fire a redux action to update the state, I always felt the lag 👎 if I am using that state to render a certain UI component. ( Like opening and closing a Material UI drawer at a rapid rate. Browser freezes after a while ). The last thing I want on my website is a browser freeze 😡
But it's always fast with the component's local state 😇
The second hook we learnt is useEffect ( );
useEffect(() => {
// Your code
}, [variables]);
Turns out, this is not just for executing some side effect code. It can control the app UX with so much minimal code 😲