Skip to content
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

Updating from the outside #50

Closed
josephrexme opened this issue Mar 1, 2018 · 3 comments
Closed

Updating from the outside #50

josephrexme opened this issue Mar 1, 2018 · 3 comments

Comments

@josephrexme
Copy link

josephrexme commented Mar 1, 2018

Is there a way to update the broadcast value from a separate file. Perhaps inside a method? Having a broadcast set with channel and value, I think I'll like something like:

// different class
import { Broadcast } from 'react-broadcast'

class Foo extend React.Component {
  someMethod() {
    Broadcast.update({name: 'Brendan Eich'})
  }
}
@josephrexme
Copy link
Author

josephrexme commented Mar 1, 2018

Asking about this because my current problem has been in my use for authentication. Where I store values in localStorage and some global states rely on those values. When a method changes the values and goes to a different route, the value remains unchanged until page is refreshed. When I set a delay with timeout though, it gets changed before getting to new route. But that also introduces some sorta race condition

@mjackson
Copy link
Member

mjackson commented Mar 3, 2018

Your question is more a question about how to use React than it is about how to use this library. A broadcast's value is updated through its <Broadcast value> prop. When your app first initializes, pull the value from local storage and keep it in state. Then, as the value changes update your state and your <Broadcast> component should automatically get the new value.

@mjackson mjackson closed this as completed Mar 3, 2018
@josephrexme
Copy link
Author

Thank you.

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

No branches or pull requests

2 participants