Reputation: 179
I have the following slice and function. How can I get values stored in my initialState?
const example = createSlice({
name: "example",
initialState: {
firstName: hello,
lastName: world
},
reducers: {}
})
export const create = (id) => {
return async (dispatch) => {
const currentState = getState()
console.log(currentState)
};
};
Do I have to use useSelector and pass values down to the function again? Ideally would like to get data directly from the already saved state
Upvotes: 9
Views: 32491
Reputation: 1745
export const create = (id) => {
return async (dispatch, getState) => {
const currentState= getState().example;
console.log(currentState)
};
};
You can access the slice state using the above code.
Upvotes: 6