Hi there, I created a side project (gradient generator) using react… But the only problem I have now is that, the generate button won’t generate gradient colors on the first click but it gets generated on the second click.
Add handleColors to the useEffect dependencies array. Then wrap the handleColors function in a useCallback and add the two dependencies clrList1 and clrList2 to its dependencies array. Doing that makes it work as expected for me.
Also, you should see a warning about the missing dependency. I also see another one about the select element in the console
Warning: Use the `defaultValue` or `value` props on <select> instead of setting `selected` on <option>.
Edit: just in case you need example code here is a Codesandbox with the changes I suggested.
And always follow the ESLint warnings, they usually point to issues that need correction (like the exhaustive-deps rule).
React is funny sometimes. You can code a bunch of stuff with no issues, and then suddenly you get some odd bug. It is often caused by how hooks work behind the scenes.