For the most part I think hooks are a game changer, but there's one area I wish could be improved - using Redux's useDispatch inside useEffect. ESLint (or better yet, the rules of hooks) enforce you to pass the dispatch object as a dependency, resulting in an effect that fires on every render.
Does it work to get the dispatch method with usedispatch outside (possibly with a usecallback) and then you can pass dispatch in to the useEffect and that shouldn't then change every render. I think that's how you are meant to manage it
I have a strong preference towards ditching the container/component split as it's hard for new react Devs to pick up and navigate the code. I'm not sure that passing in an extra prop is too much effort, but it is subjective
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.
For the most part I think hooks are a game changer, but there's one area I wish could be improved - using Redux's
useDispatch
insideuseEffect
. ESLint (or better yet, the rules of hooks) enforce you to pass the dispatch object as a dependency, resulting in an effect that fires on every render.mapDispatchToProps
to the rescue!Totally agree. Encountered the same issue too and it's annoying to manually disable the linter for this line.
Does it work to get the dispatch method with usedispatch outside (possibly with a usecallback) and then you can pass dispatch in to the useEffect and that shouldn't then change every render. I think that's how you are meant to manage it
I guess it should work, but if you're going through so much trouble,
mapDispatchToProps
will probably be easierI have a strong preference towards ditching the container/component split as it's hard for new react Devs to pick up and navigate the code. I'm not sure that passing in an extra prop is too much effort, but it is subjective