Working On Stale State And Hooks

10/02/20191 Min Read — In Lab, React.js, JavaScript

Learning the fundamentals of React was reasonably straightforward.
React.js adds a lot of abstraction over JavaScript. But after you've got the basic building blocks down, you can get quite far.

You can profit from the vast ecosystem, and the tons of available material (tutorials, StackOverflow, blog posts, etc.).

But the more you work with state, props, you realize that there are a lot of pitfalls.

You probably don't need derived state, but sometimes you do. You're working with stale state; then you try to use a React ref.
Mix that up with useEffect, because setState is asynchronous. You need to access the updated state, but each render closes over the previous state.

It gets complex, really fast.
There are so many ways you can go wrong.

I'm interested to see if Svelte.js suffers from the same problems.