title: React Redux Toolkit: How can I can store my initialState to localStorage using createSlice?
body: <p>I'm a bit too confused about how can I Store the initialState of my taskSlice into my localStorage. Can you please help me with how can I solve this problem? The result that I want is if the app runs the initialState will be store in the localStorage. Coz what I'm doing is using useSelector inside my component then useEffect to know if there's an existing localStorage value. If false it will store the state inside the localStorage.</p>
  <p><strong>taskSlice.js</strong></p>
  <pre><code>import { createSlice } from '@reduxjs/toolkit';
  import { v4 as uuidv4 } from 'uuid';
  
  const initialState = [
    {
      _id: uuidv4(),
      title: 'Learn React',
      desc: 'Nec ullamcorper sit amet risus nullam eget felis.',
      isProgress: false,
      isComplete: false,
      priority: 'Minor',
      created: 'johndoe',
      assigned: 'Doe John',
      dateCreated: new Date(),
      dateDue: new Date(),
    },
  ];
  
  export const taskSlice = createSlice({
    name: 'tasks',
    initialState: initialState,
    reducers: {
  addTodo: (state, action) =&gt; {
        state.push({
          _id: uuidv4(),
          title: action.payload.taskInfo.title,
          desc: action.payload.taskInfo.description,
          isProgress: false,
          isComplete: false,
          priority: action.payload.taskInfo.priority,
          dateCreated: new Date(),
          created: action.payload.taskInfo.created,
          assigned: action.payload.taskInfo.assigned,
          dateDue: action.payload.taskInfo.dateDue,
        });
      },
    },
  });
  
  export const { addTodo } = taskSlice.actions;
  
  export const taskSelector = (state) =&gt; state.tasks;
  
  export default taskSlice.reducer;
  </code></pre>