beekai-oss / little-state-machine

📠 React custom hook for persist state management
https://lrz5wloklm.csb.app/
MIT License
1.48k stars 53 forks source link

Help with the LocalStorage and Next.JS #116

Closed MatheusLopesDev99 closed 2 years ago

MatheusLopesDev99 commented 2 years ago

Hey Guys, i am using the little-state-machine to store some data, but the default of the library is to use sessionStorage.

I am trying to change to localStorage but without success, returns error:

e.setItem is not a function

import React from "react";
// Sheets
import "../styles/globals.css";
import "../styles/globals-mobile.css";
import "../styles/bootstrap.min.css";
import { SnackbarProvider } from "notistack";
import { StateMachineProvider, createStore, setStorageType } from "little-state-machine";

createStore(
  {
    user: null,
    oferta: {},
    mensagensAgendadas: [],
    metricas: {},
  },
  {
    storageType: window.localStorage
  }
);

function MyApp({ Component, pageProps }) {
  return (
    <>
      <StateMachineProvider>
        <SnackbarProvider maxSnack={3}>
          <Component
            {...{
              ...pageProps,
            }}
          />
        </SnackbarProvider>
      </StateMachineProvider>
    </>
  );
}

export default MyApp;
bluebill1049 commented 2 years ago

could you share a codesandbox on the localstorage usage?