suthSlice.js file - foday/bug-tracker GitHub Wiki
import {createSlice} from '@reduxjs/toolkit'
const slice = createSlice({ name:"auth", initialState:{ admin:false, LoggedIn:false, }, reducers:{ signIn:(state, action)=>{ const {name,password} = action.payload; state.LoggedIn = true; state.admin = true; }, signOut:(state,action)=>{ state.LoggedIn = false; state.admin = false;
},
createUser:(state,action)=>{
}
}
})
export default slice.reducer;
export const {signIn,signOut,createUser} = slice.actions;
NOTES suthSlice.js file start by importing createslice from reduxjs toolkit. createSlice takes an object of reducer functions, a slice name, and an initial state value and lets us auto-generate action types and action creators, based on the names of the reducer functions that we supply. It also helps you organize all of your Redux-related logic for a given slice into a single file. Then store createSlice object in the slice constant. reducers object: A reducer is a function that determines changes to an application's state. It uses the action it receives to determine this change. We have tools, like Redux, that help manage an application's state changes in a single store so that they behave consistently. Reducers value is another object with sighIn as a name and i think '(state, action) is a value with an anonymous function. There is a signIn, sighOut and createUser. This is the file for authentication