Skip to content

Update README.md #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

Merged
merged 1 commit into from
Jun 3, 2018
Merged

Conversation

jasanst
Copy link
Contributor

@jasanst jasanst commented Jun 3, 2018

Using this.state in setState is discouraged due to potential timing issues.

Might want to rethink the union type example, addition to null would give a type error and the fix looks unwieldy.

Using this.state in setState is discouraged due to potential timing issues.

Might want to rethink the union type example, addition to null would give a type error and the fix looks unwieldy.
@ghost
Copy link

ghost commented Jun 3, 2018

this.state in setState is NOT discouraged at all in the current changed example you changed

@jasanst
Copy link
Contributor Author

jasanst commented Jun 3, 2018

It's almost identical to the example of wrong usage in the documentation?

https://reactjs.org/docs/state-and-lifecycle.html#state-updates-may-be-asynchronous

@ghost
Copy link

ghost commented Jun 3, 2018

So strange! I maintain at work hundreds of components in big UI projects and didn't bump with any issue for almost 20 months. (Project still adding pages/components til now)!

@tsiq-swyx
Copy link
Contributor

thanks @jasanst, i agree. i was just being lazy :)

@tsiq-swyx tsiq-swyx merged commit f5ca9eb into typescript-cheatsheets:master Jun 3, 2018
@ghost
Copy link

ghost commented Jun 13, 2018

@jasanst @tsiq-swyx

I just bumped with this issue today at work when I used async componentDidUpdate (That contains await and after the await resolve it will set the state) and concluded the following:

"You MUST use Functional setState in React if you've async usages of setState (Like after await).. so you can catch up the last state snapshot correctly without overriding the things"

@ghost
Copy link

ghost commented Jun 13, 2018

Other than that case, I use setState as regular in Sync operations 👍

@tsiq-swyx
Copy link
Contributor

tsiq-swyx commented Jun 16, 2018 via email

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

Successfully merging this pull request may close these issues.

2 participants