I have created a member registration function.
I want to pass the value of formState.values from useCallback Hook to axios.post.
However, when I put formState.values in useCallback dependencies in the handleSubmit function, a ',' expected. type error occurs.
What should I do? You need to put the values array values in formState as axios argument.
Can't you put formState.values in deps, axios argument values like this?
How do I pass the value value as an argument?
const [formState, setFormState] = useState<formState>({
isValid: false,
values: {},
touched: {},
errors: {},
});
const handleSubmit = useCallback((event: FormEvent) => {
event.preventDefault();
axios.post<Login>(
'http://www.minsususu.com/login',
{formState.values},
{
withCredentials: true,
},
)
.then(response => {
const { accessToken } = response.data;
axios.defaults.headers.common['Authorization'] = `Bearer ${accessToken}`;
router.history.push('/');
})
.catch(error => {
console.log(error);
});
}, [formState.values])
would say the problem is in the post call:
axios.post<Login>(
'http://www.minsususu.com/login',
formState.values, // or {values: formState.values}
{ withCredentials: true },
)