title: Access data from store in App.js. - Redux Persist
body: <p>i am stuck with this Problem. Any help would be appreciated.</p>
  <p>I am using Redux Persist in my react native app and i want to access data stored in state 'number' from store.js in App.js.</p>
  <p>I have pasted my code below.</p>
  <p>Here is my actions.js</p>
  <pre><code>
  export const setNumber = number =&gt; dispatch =&gt; {
    dispatch({
      type: SET_NUMBER,
      payload: number,
    });
  };
  </code></pre>
  <p>reducers.js</p>
  <pre><code>import {SET_NUMBER} from './actions';
  
  const initialState = {
    number: [],
  };
  
  function numberReducer(state = initialState, action) {
    switch (action.type) {
      case SET_NUMBER:
        return {...state, number: action.payload};
      default:
        return state;
    }
  }
  
  export default numberReducer;
  
  </code></pre>
  <p>store.js</p>
  <pre><code>import {createStore, combineReducers, applyMiddleware} from 'redux';
  import thunk from 'redux-thunk';
  import AsyncStorage from '@react-native-async-storage/async-storage';
  import {persistStore, persistReducer} from 'redux-persist';
  
  import numberReducer from './reducers';
  
  const persistConfig = {
    key: 'root',
    storage: AsyncStorage,
    whitelist: ['number'],
  };
  
  const rootReducer = combineReducers({
    numberReducer: persistReducer(persistConfig, numberReducer),
  });
  
  const store = createStore(rootReducer, applyMiddleware(thunk));
  const persistor = persistStore(store);
  
  export {store, persistor};
  
  </code></pre>
  <p>App.js</p>
  <pre><code>import React, {Component} from 'react';
  import {View, Text, SafeAreaView, Button} from 'react-native';
  import {NavigationContainer} from '@react-navigation/native';
  import {createNativeStackNavigator} from '@react-navigation/native-stack';
  import {Provider} from 'react-redux';
  import {store, persistor} from './redux/store';
  import {PersistGate} from 'redux-persist/integration/react';
  import {connect} from 'react-redux';
  
  import Login from './screens/Login';
  import Home from './screens/Home';
  import Details from './screens/Details';
  
  const Stack = createNativeStackNavigator();
  
  function App() {
    if (number == null) {
      return (
        &lt;NavigationContainer&gt;
          &lt;Stack.Navigator&gt;
            &lt;Stack.Screen
              name=&quot;Home&quot;
              component={Home}
              options={{
                headerStyle: {
                  backgroundColor: 'lightblue',
                },
              }}
            /&gt;
          &lt;/Stack.Navigator&gt;
        &lt;/NavigationContainer&gt;
      );
    } else {
      return (
        &lt;Provider store={store}&gt;
          &lt;PersistGate loading={null} persistor={persistor}&gt;
            &lt;NavigationContainer&gt;
              &lt;Stack.Navigator&gt;
                &lt;Stack.Screen
                  name=&quot;Login&quot;
                  component={Login}
                  options={{
                    headerStyle: {
                      backgroundColor: 'lightblue',
                    },
                  }}
                /&gt;
                &lt;Stack.Screen
                  name=&quot;Home&quot;
                  component={Home}
                  options={{
                    headerStyle: {
                      backgroundColor: 'lightblue',
                    },
                  }}
                /&gt;
                &lt;Stack.Screen
                  name=&quot;Details&quot;
                  component={Details}
                  options={{
                    headerStyle: {
                      backgroundColor: 'lightblue',
                    },
                  }}
                /&gt;
              &lt;/Stack.Navigator&gt;
            &lt;/NavigationContainer&gt;
          &lt;/PersistGate&gt;
        &lt;/Provider&gt;
      );
    }
  }
  
  export default App;
  
  </code></pre>
  <p>I want to access the data in 'number' so that my 'if condition' would work in App.js Right now it says variable 'number' can not be found which is understandable. Is there any way that i can access data in 'number' for if condition to work.
  Thanks in advance.</p>