Skip to content

Instantly share code, notes, and snippets.

@Sathiyapramod
Last active February 25, 2024 07:09
Show Gist options
  • Save Sathiyapramod/699d4f240e9c279d102daa9783324d98 to your computer and use it in GitHub Desktop.
Save Sathiyapramod/699d4f240e9c279d102daa9783324d98 to your computer and use it in GitHub Desktop.
Redux variables authSlice file
// 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