I'm working on crud operations on Next.js by using Typescript. Also Redux is implemented to the project.
This is my [id].tsx file to edit the data.
const dispatch = useDispatch<ThunkDispatch<any, any, any>>();
const category = useSelector((state:any) => state.category.categorySelected[0]);
const onSubmit = (data) => {
dispatch(updateCategory(data));
}
useEffect(() => {
dispatch(getCategoryById({ id: parseFloat(router.query.id ) }));
if (category) {
setValue("id", category.id);
setValue("name", category.name);
}
}, [JSON.stringify(category)]);
In here,data that inside of the updateCategory(data) is giving the error.
Also,{ id: parseFloat(router.query.id ) } part is the giving the same error too.
categorySlice.js file:
export const updateCategory = createAsyncThunk("category/updateCategory", async (item, ) => {
return axios.put(`${process.env.baseSite}/api/category/update`, item).then((response) => {
Router.push("/admin/category");
});
});
export const getCategoryById = createAsyncThunk("category/getCategoryById", async (item) => {
return axios.post(`${process.env.baseSite}/api/category/getByIdCategory`, item).then((response) => {
return response.data;
});
});
Thanks.
I tried giving type by using interface but i couldn't have any results.