{"size": 848, "ext": "js", "max_stars_repo_path": "src/redux/features/themeSlice.js", "max_stars_repo_name": "jma8774/Snackies", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/redux/features/themeSlice.js", "max_issues_repo_name": "jma8774/Snackies", "max_issues_repo_issues_event_min_datetime": "2022-02-20T02:44:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-20T02:44:47.000Z", "max_forks_repo_path": "src/redux/features/themeSlice.js", "max_forks_repo_name": "jma8774/Snackies", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 35.3333333333, "max_line_length": 93, "alphanum_fraction": 0.6863207547}
import { createSlice } from '@reduxjs/toolkit'
import Cookies from 'universal-cookie';

const cookies = new Cookies();
// createSlice is part of the Redux Toolkit which is the recommended way to use Redux
// It simplifies the old ways of creating reducers and then having to create actions for each
// Better file managment this way
export const themeSlice = createSlice({
  name: 'theme',
  // Cookie doesn't get stored as a bool but as a string, so we have to do
  //    "true" === "true" --> true
  //    "false" === "true" --> false
  initialState: cookies.get("theme") === undefined ? true : cookies.get("theme") === "true",
  reducers: {
    toggle: (state) => {
      return !state
    },
  },
})

// Action creators are generated for each case reducer function
export const { toggle } = themeSlice.actions

export default themeSlice.reducer