Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
Put array values ​in `usecallback deps`

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])
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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 },
)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!