O'Reilly logo

React Native Cookbook by Crysfel Villa, Stan Bershadskiy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Setting up the store

The store is responsible for saving the information on the state. It's a single global object that can be accessed via getState.

In this recipe, we will bring together the actions and the reducer we created in the previous recipes. We will use the existing actions to start saving data on the store. We will also learn how to log changes on the state by subscribing to the store changes.

How to do it...

  1. Let's open the src/redux/index.js file and import the createStore function from the redux package:
            import { combineReducers, createStore } from 'redux'; 
    
  2. Creating the store is extremely simple; all we need to do is call the function from step 1 and send the reducers as the first parameter:
            const store = createStore(reducers); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required