Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

observe() Dependent on State #15

Closed
DavidHarrison opened this issue Apr 10, 2015 · 2 comments
Closed

observe() Dependent on State #15

DavidHarrison opened this issue Apr 10, 2015 · 2 comments

Comments

@DavidHarrison
Copy link

I have a React component with a number of tabs, each dependent on different Parse queries. I have made observe() dependent on the currently selected tab, which is stored in the component's state. When observe is called, it is done with the state before the setState() call that sets off the process. However, render is called with the state after setState(), which misaligns the the component's data with the data needed by the tab.

I believe this is because React does not update state until just before rendering (facebook/react#629).

Will this be fixed with #1?

@andrewimm
Copy link
Contributor

the observe method takes nextProps and nextState as arguments. That's because we fire it from componentWillUpdate, which is called before state is updated, as you noted.
If you want the previous state, it'll be at this.state. If you want the new state, use the second argument of observe.

@DavidHarrison
Copy link
Author

That works great. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants