From the course: React: Software Architecture

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Sharing Recoil state

Sharing Recoil state

- [Narrator] Okay, before we move on from recoil, there are a few more things that I want to show you that are important to know before using it. The first thing I want to show you is how recoil allows our components to share state. So before we do that, let's start by deleting some of our unneeded imports here. Just to clean up a little bit. First of all, let's imagine that our application has two CounterButtons instead of one. Well, with recoil, these will automatically share their state. So let's take a look at this in our browser, and we can see that if we click on this, it will automatically increment both. And if we change the incrementBy, since that's using recoil as well, that will automatically make the exact same change to both as well. Now this may or may not be what you want, which is why it's important to know that this is a basic feature of recoil. If we were using the useState hook like we saw before,…

Contents