Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

setGlobal in componentDidMount should be synchronous. #14

Open
quisido opened this issue Nov 10, 2018 · 5 comments
Open

setGlobal in componentDidMount should be synchronous. #14

quisido opened this issue Nov 10, 2018 · 5 comments
Labels
feature A new feature is requested. help wanted The owner cannot resolve this on their own.

Comments

@quisido
Copy link
Collaborator

quisido commented Nov 10, 2018

Also did update and set global callback

Async elsewhere

@quisido quisido self-assigned this Nov 19, 2018
@quisido quisido added the feature A new feature is requested. label Nov 19, 2018
@umbertoghio
Copy link
Contributor

Why not declaring componentDidMount async and do await setGlobal?

@quisido
Copy link
Collaborator Author

quisido commented Jan 28, 2019

setState is synchronous in componentDidMount. setGlobal should mimic that behavior. It's just a matter of it being possible in all implementations.

You can likely find details from the React team on why setState is synchronous sometimes. I'd love to link it, but I'm restricted to mobile for a little longer as I'm in the process of moving.

@quisido quisido removed their assignment Apr 18, 2019
@quisido quisido changed the title setGlobal in componentDidMount should be synchronous setGlobal in componentDidMount should be synchronous. Apr 28, 2019
@quisido quisido added the help wanted The owner cannot resolve this on their own. label May 15, 2019
@bpas247
Copy link

bpas247 commented Jun 3, 2019

@CharlesStover Are you referring to this comment?

@matteocargnelutti
Copy link

Hi @CharlesStover ,

I feel like having a third parameter to force synchronicity could be interesting.

As of now, what would be the best way of making synchronous calls to setGlobal, regardless of the context ?

Thank you in advance,

@stahlmanDesign
Copy link

stahlmanDesign commented Sep 16, 2019

I'm not sure this is related, but I've noticed that when I setGlobal in componentDidMount (after async fetching of data), it sometimes does not cause the page to render.
I have to use a callback and force update:

setGlobal({ myValue: val }, ()=>{
  this.forceUpdate()
})

EDIT I figured out my problem. I forgot that reactn requires a default value for global state to trigger a re-render the first time it is changed: #57

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature A new feature is requested. help wanted The owner cannot resolve this on their own.
Projects
None yet
Development

No branches or pull requests

5 participants