I am trying to create a player, using a POST
request but getting the error as promise rejected
in redux devtool.
But I can see the data on the UI. I am using createAsyncThunk
and createEntityAdapter
:
createAsyncThunk
export const addPlayer = createAsyncThunk(
'players/addPlayer',
async (formData) => {
await fetch('/api/players', {
headers,
method: 'POST',
body: JSON.stringify(formData),
});
await response.json();
console.log(formData);
return formData;
}
);
extraReducers builder
.addCase(addPlayer.fulfilled, (state, action) => {
adapter.addOne(state, action.payload);
})
handler
case 'POST': {
const player = await controller.create(req.body);
return res.status(201).json(player);
}
SubmitfromFunction
const handleSubmitData = (event) => {
event.preventDefault();
//fix this validation later
if (!formData) {
alert('Please fill from');
} else {
dispath(addPlayer(formData));
// window.location.reload();
console.log(formData);
}
};
screenshot of Redux Devtool:
The framework I am using is NextJs here. Does anyone know what am I missing or doing wrong?