I need to implement a reducer in my react native application. The store constant is defined as follows:
export const USER_PROFILE = 'USER_PROFILE';
This is the content of action.js file:
import {USER_PROFILE} from '../constants/index';
export function userProfile(userReducer) {
return {
type: USER_PROFILE,
payload: {
email: '',
},
};
}
The error seems to be related to the userReducer. The error message states that customerReducer is not recognized as a function.
import {USER_PROFILE} from '../constants/index';
const initialState = {
userProfile: '',
};
const customerReducer = (state = initialState, action) => {
switch (action.type) {
case USER_PROFILE:
return {
...state,
userProfile: action.payload,
};
default:
return state;
}
};
export default customerReducer;
In addition, the email has been declared as a state variable:
const [email, setEmail] useState('')
The reducer is being accessed here:
const customerReducer = useSelector(state => state.userProfile);
Now, it needs to be dispatched using the useDispatch method.
const dispatch = useDispatch();
...
dispatch(customerReducer(email));