Estou fazendo um aplicativo onde uso o redux toolkit e o localstorage para salvar o tema.
Eu tenho esta fatia:
import { createSlice } from "@reduxjs/toolkit";
const mode = !localStorage.getItem("theme")
? ""
: JSON.parse(localStorage.getItem("theme")); //the error is on this line
const initialState = {
mode: mode,
};
const ThemeSlice = createSlice({
name: "theme",
initialState,
reducers: {
toggleTheme: (state) => {
state.mode = state.mode === "light" ? "dark" : "light";
},
},
});
export const { toggleTheme } = ThemeSlice.actions;
export default ThemeSlice.reducer;
mas está me dando um erro:Argument of type 'string | null' is not assignable to parameter of type 'string'.
O que posso fazer para remover esse erro?