When to use ES6 class based React components vs. functional ES6 React components?

New Answer: Much of the below was true, until the introduction of React Hooks. componentDidUpdate can be replicated with useEffect(fn), where fn is the function to run upon rerendering. componentDidMount methods can be replicated with useEffect(fn, []), where fn is the function to run upon rerendering, and [] is an array of objects for which … Read more

React setState not Updating Immediately

You should invoke your second function as a callback to setState, as setState happens asynchronously. Something like: this.setState({pencil:!this.state.pencil}, myFunction) However in your case since you want that function called with a parameter you’re going to have to get a bit more creative, and perhaps create your own function that calls the function in the props: … Read more

Why do we need middleware for async flow in Redux?

What is wrong with this approach? Why would I want to use Redux Thunk or Redux Promise, as the documentation suggests? There is nothing wrong with this approach. It’s just inconvenient in a large application because you’ll have different components performing the same actions, you might want to debounce some actions, or keep some local … Read more