-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connected components cannot use new 16.3 lifecycles #915
Comments
I'm not sure I understand that example. The Can you put together a minimal repro of this issue in a CodeSandbox or something? |
Sure thing... |
Hmm. Perhaps it's due to our use of |
I was having a heck of a time reproducing with most recent versions of dependencies on codesandbox, so that would make sense... I'll upgrade and check... |
Yep, you are right, most recent patch version fixes this. Thanks for the quick feedback, and sorry for wasting your time! |
Is this actually addressed? It seems like If I understand React's warning correctly, this means the |
The problem here is that We are still using a |
@markerikson is it correct to dipatch() something inside gDSFP or inside cDU? |
No, gDSFP must be pure and contain no dispatch calls. Dispatching in cDU is okay-ish. Although it's still not that great from performance perspective to dispatch in response to re-rendering. But you were already doing it. |
@gaearon Actually, I already have it inside cWRP (if props change, I compare it and dispatch something to reducer).. but now that I've updated the react version I'm trying to migrate it. Humm.. is there a correct way to dispatch something when props change? |
@vctormb cDU is the recommended way: https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#side-effects-on-props-change But I'd probably ask what your cWRP is responding to. Could that be responsible for dispatching the action? Could you push the state transformation back to the store itself? There is probably a larger refactor that will actually put you in a better position not just for React async stuff, but as your app changes over time. |
@timdorr Yes! I already read this blog! Btw, it is really great, thanks! Well, this dispatch I'm using to clear some values inside reducer because they are related to redux-form. So I need to use some action creators to change some values there. |
I know that there is still much consideration going into #890 so I don't mean to rush, but I thought you might be interested to know:
It looks like React 16.3 exposes the new lifecycles in a way that disallow for using the old componentWill* at the same time as new lifecycles.
Something that looks roughly like this:
will get this warning:
which I didn't understand until I saw that the implementation details of
connect
use inheritance to add those lifecycles.My workaround in this first case I found in my code is pretty easy to fix (I was just using the
connect
to get a dispatch method) but I bet people are going to start running into this as they upgrade to 16.3.Sending my best to your efforts in #890 !
The text was updated successfully, but these errors were encountered: