-
Notifications
You must be signed in to change notification settings - Fork 10
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
react connectors don't work on react-native #52
Comments
Whaaat, sounds like a bug in react-native? I'll wait for an answer from the react-native team. According the docs this hook should be called before any rerender regardless of reason for render: "Note that this method is fired on every render, regardless of the cause. " |
apparently only a thing since 16.4 facebook/react#12898 but yea i think it's a behaviour that needs to be aligned in react-native |
Will have to read and digest https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html |
Hi any updates on this? Have tried downgrading react to 16.3 but it's very hard to to with expo, react-native and react-native-web together in a single project -_- (it works in react-native-web though). Should I take a look at using hooks instead maybe? |
I had a quick look at this. I think the issue is not necessarily anything to do with getDerivedStateFromProps. To me the issue seems to do with this line detecting DOM: var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement) If I wonder if there's a way to differentiate between Browser, Server and React Native. |
If that's the case, could just have |
Fix released in 3.4.1. Instead of looking for |
If we subscribed on the server, componentWIllUnmount is never called on the server so the observers would never get cleaned up and will add more on each render |
That's why I added the isServer (or canUseDom previously) check in the first place. But I then quickly realised that you don't reuse the same atom across renders. Because the state could mix up, if you preload user A into atom for request 1, but user B for request 2, you don't want to be reusing atom anyway. This means that after each request/render the atom gets garbage collected. |
Thanks for looking into it! |
@zyk interesting, but what do you use |
@zyk could you paste the snippet of code that's not working for you as expected? |
I put the console logging directly in node_modules/tiny-atom/react.js getDerviedStateFromProps, I did not use getDerived.. myself. Oh didn't see was a react-native example. |
Upgrading to latest react worked, thanks! |
Awesome, glad to hear. Let me know if you run into any other issues. Also, checkout |
getDerivedStateFromProps
behaves differently in react and react-native: facebook/react-native#20759In react-native, this is only called when props update, not when state updates. This means if you have a state change that does not cause the parent of a connected component to pass down new props, we don't derived the new mapped props.
The text was updated successfully, but these errors were encountered: