Course lesson

Define Actions in a Zustand-like Store to Modify React State

At this point in our code, we have working module state that is similar to Zustand. If you look closely at the code you’ll notice that we are defining actions in our components. This works for some but you might want to define those actions when you create a...

Duration
2 min
Access
Pro
Transcript
Available

At this point in our code, we have working module state that is similar to Zustand. If you look closely at the code you’ll notice that we are defining actions in our components. This works for some but you might want to define those actions when you create a store.

We will modify createStore to accept a createState function and use that function to initialize and update our state. This allows us to define actions while creating a store. We can use those defined actions in our components without having to implement any logic inline.