Hey there :) Every time I see a function that is called toggleSomething and then accepts a parameter I make this comment. I'd either rename it to setSomething if it accepts a parameter or remove the need for the param instead. In your example you could achieve it like this:
FYI I've used useCallback so that the function does not change every time the context provider renders. This way consumers do not need to update necessarily even though nothing has changed.
Hey Philipp, thank you for the tip! Your code is much cleaner and makes much more sense for that function. Duly noted! And yes I understand your use of useCallback, so that the function is not redefined on every render of the component. Thank you for taking your time to read my article. Appreciate it!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hey there :) Every time I see a function that is called
toggleSomething
and then accepts a parameter I make this comment. I'd either rename it tosetSomething
if it accepts a parameter or remove the need for the param instead. In your example you could achieve it like this:FYI I've used
useCallback
so that the function does not change every time the context provider renders. This way consumers do not need to update necessarily even though nothing has changed.Hey Philipp, thank you for the tip! Your code is much cleaner and makes much more sense for that function. Duly noted! And yes I understand your use of useCallback, so that the function is not redefined on every render of the component. Thank you for taking your time to read my article. Appreciate it!