Skip to content
Advertisement

Tag: state

How can I wait for setState to finish before triggering a function in React?

Here’s my situation: on this.handleFormSubmit() I am executing this.setState() inside this.handleFormSubmit(), I am calling this.findRoutes(); – which depends on the successful completion of this.setState() this.setState(); does not complete before this.findRoutes is called… How do I wait for this.setState() inside of this.handleFormSubmit() to finish before calling this.findRoutes()? A subpar solution: putting this.findRoutes() in componentDidUpdate() this is not acceptable because there will

Where to write to localStorage in a Redux app?

I want to persist some parts of my state tree to the localStorage. What is the appropriate place to do so? Reducer or action? Answer Reducer is never an appropriate place to do this because reducers should be pure and have no side effects. I would recommend just doing it in a subscriber: Before creating the store, read those persisted

Advertisement