text: import { useMemo } from 'react'
  import reduxThunk from 'redux-thunk'
  import { createStore, applyMiddleware } from 'redux'
  import reducers from './reducers'
  
  let store = null
  const initialState = {
  }
  
  export const initStore = (preloadedState = initialState) => createStore(
    reducers,
    preloadedState,
    applyMiddleware(reduxThunk)
  )
  
  export const initializeStore = (preloadedState) => {
    let _store = store ?? initStore(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 && store) {
      _store = initStore({
        ...store.getState(),
        ...preloadedState,
      })
      // Reset the current store
      store = undefined
    }
  
    // For SSG and SSR always create a new store
    if (typeof window === 'undefined') return _store
    // Create the store once in the client
    if (!store) store = _store
    return _store
  }
  
  export const useStore = (initialState) => useMemo(() => initializeStore(initialState), [initialState])
  