Last active
February 25, 2024 07:09
-
-
Save Sathiyapramod/699d4f240e9c279d102daa9783324d98 to your computer and use it in GitHub Desktop.
Redux variables authSlice file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// file path - redux/modules/auth.js | |
// To declare and initiate the redux variables | |
//actions | |
export const USERNAME = "project/signin/username"; | |
export const PASSWORD = "project/signin/password"; | |
//actions type | |
export const fetchUsername = (input) => { | |
return { type: USERNAME, payload: input }; | |
}; | |
export const fetchPassword = (input) => { | |
return { type: PASSWORD, payload: input }; | |
}; | |
//setting the initial states | |
export const initialState = { | |
username: null, | |
password: null, | |
}; | |
//reducer function (which is by default will be exported) | |
export default function reducer(state = initialState, action) { | |
switch (action.type) { | |
case USERNAME: | |
return { ...state, username: action.payload }; | |
case PASSWORD: | |
return { ...state, password: action.payload }; | |
default: | |
return state; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment