title: Nextjs Redux getState undefined
body: <p>Hi i have simple project in <code>Nextjs</code> .I want to get the state of redux store but when i am trying to  use <code>store.getState</code> it's throwing one <code>error</code> <code>getState</code> of undefined. And I have one simple <code> vinalla javascript</code> file i want to use <code>getState</code> inside that file also .How can i do that.</p>
  <p>//store.js</p>
  <pre><code>import { useMemo } from &quot;react&quot;;
  import { createStore, applyMiddleware } from &quot;redux&quot;;
  import { composeWithDevTools } from &quot;redux-devtools-extension&quot;;
  import { persistReducer } from &quot;redux-persist&quot;;
  import storage from &quot;redux-persist/lib/storage&quot;;
  import { rootReducer } from &quot;./reducer&quot;;
  import { exampleInitialState } from &quot;./reducer&quot;;
  let store;
  
  const persistConfig = {
    key: &quot;primary&quot;,
    storage,
    whitelist: [&quot;exampleData&quot;, &quot;count&quot;], // place to select which state you want to persist
  };
  
  const persistedReducer = persistReducer(persistConfig, rootReducer);
  
  function makeStore(initialState = exampleInitialState) {
    return createStore(
      persistedReducer,
      initialState,
      composeWithDevTools(applyMiddleware())
    );
  }
  
  export const initializeStore = (preloadedState) =&gt; {
    let _store = store ?? makeStore(preloadedState);
  
    // After navigating to a page with an initial Redux state, merge that state
    // with the current state in the store, and create a new store
    if (preloadedState &amp;&amp; store) {
      _store = makeStore({
        ...store.getState(),
        ...preloadedState,
      });
      // Reset the current store
      store = undefined;
    }
  
    // For SSG and SSR always create a new store
    if (typeof window === &quot;undefined&quot;) return _store;
    // Create the store once in the client
    if (!store) store = _store;
  
    return _store;
  };
  
  export function useStore(initialState) {
    const store = useMemo(() =&gt; initializeStore(initialState), [initialState]);
    return store;
  }
  </code></pre>
  <p>//_app.js</p>
  <pre><code>import { useStore } from '../store'
  import { Provider } from 'react-redux'
  import { persistStore } from 'redux-persist'
  import { PersistGate } from 'redux-persist/integration/react'
  
  export default function App({ Component, pageProps }) {
    const store = useStore(pageProps.initialReduxState)
    const persistor = persistStore(store, {}, function () {
      persistor.persist()
    })
  
    return (
      &lt;Provider store={store}&gt;
        &lt;PersistGate loading={&lt;div&gt;loading&lt;/div&gt;} persistor={persistor}&gt;
          &lt;Component {...pageProps} /&gt;
        &lt;/PersistGate&gt;
      &lt;/Provider&gt;
    )
  }
  </code></pre>
  <p>vinall.js - How can i use <code>store.getState</code> in this file</p>
  <pre><code>import React from &quot;react&quot;;
  import { useStore } from &quot;../store&quot;;
  function vanilla() {
    
    return &lt;div&gt;i m vanilla js file&lt;/div&gt;;
  }
  
  export default vanilla;
  </code></pre>
  <p>//Also in this file</p>
  <pre><code>import { useStore } from &quot;../store&quot;;
  function simplejs() {
    
    let state=useStore.getState();
    return state.tods;
  }
  </code></pre>