esamattis / redux-hooks

⚓ React Hooks implementation for Redux
http://npm.im/@epeli/redux-hooks
MIT License
96 stars 4 forks source link

great idea for the warning! #11

Open gcloeval opened 5 years ago

gcloeval commented 5 years ago

This few lines here:

if (process.env.NODE_ENV !== "production") {
                const check = mapStateRef.current(state);
                if (!is(check, res)) {
                    console.warn(
                        "useMapState returns new identity on every run. This causes the component to render on every Redux state change. Consider use using useSelect().",
                        res,
                    );
                }
            }

this is so so excellent. You have saved me so much time. It cought every single place I mistankely was returning new identities and/or in general misconfiguring stuff. I know you are sort of using this as a prototyping for official redux hooks, so I just want to encourage you that this sort of warning is also included there.

esamattis commented 5 years ago

Thanks! Appreciate the feedback. Need to add this for useSelect too.

And add component stack traces once React.warn() ships: https://github.com/facebook/react/pull/15170

esamattis commented 5 years ago

Oh, just be clear I'm not an author of react-redux. I've contributed to it few times but I have no direct influence on its API design.

But feedback like this can of course influence @markerikson and other authors indirectly.

The hooks api discussion is over here https://github.com/reduxjs/react-redux/issues/1179