Hi all , Many people started using react-hooks including me . The most common issue people face while using hook is infinite loop
To avoid such infinite loop all are aware of using the conditions in the array brackets like
We can also use state variables inside the array brackets
Whenever the state value changes the useEffect will be rendered again
Now the issue what I'm trying to represent is giving un predictable values inside the array brackets
In the above image I'm having the state variable of the type array which consists of multiple objects , when the changes are made react checks for the condition inside the useEffect, whether to re-render the useEffect or not.
Here is the problem since we didn't mention the particular value inside the array of useEffect , so whenever the value inside the state changes react doesn't find any difference and the useEffect is not rendered again even if I change the object value name:'full stack developer'
This happens because react can't predict the value changed inside the particular object inside the array.
*Note: useEffect will identify the change if any new object is added to the array *
Thanks for reading!
Happy Coding !
I think that your article would be greatly improved if you suggested a solution or two to the problem you present.
Just my two pennies.