Checked this, but pass one argument and destructing did not help.
How do you pass arguments to createAsyncThunk in redux toolkit?
Have this:
export const login = createAsyncThunk("users/login", async (user, params) => {
const { name, data } = params;
const { userContext } = await axios({
method: "post",
url: `loginEmail`,
data: data,
headers: {
"Content-Type": "application/json",
},
});
return userContext;
});
and got this error:
ERROR in src/components/CreatePost.tsx:142:25
TS2554: Expected 0 arguments, but got 1.
140 | onClick={() => {
141 | dispatch(
> 142 | login({
| ^
> 143 | email: "j",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 144 | password: "S",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 145 | })
| ^^^^^^^^^^^^^^^^^^^^
146 | );
147 | }}
When calling:
dispatch(
login({
email: "janoech",
password: "xxx",
}))
importing here:
import { login } from "../slices/User";
and the slice:
const userSlice = createSlice({
name: "user",
initialState: {
userContext: null,
},
reducers: {},
extraReducers: (builder) => {
builder.addCase(getUser.fulfilled, (state, payload) => {
state.userContext = payload;
});
builder.addCase(logout.fulfilled, (state, payload) => {
state.userContext = null;
});
builder.addCase(login.fulfilled, (state, { payload }) => {
state.userContext = payload;
});
},
});
export default userSlice.reducer;