A
A
Alexander2021-08-05 11:45:56
JavaScript
Alexander, 2021-08-05 11:45:56

How to get data from fetch in another file?

How can I get data from fetch in another file?
Need to get response in Form.tsx file for onSubmit

from-api.ts

await fetch('https://jsonplaceholder.typicode.com/todos')
      .then((response) => {
        return response.json()
      })
      .then((data) => {
        console.log(data)
      })


form.tsx
const onSubmit: SubmitHandler<IFormInputs> = async (data) => {
    const { res } = await FormApi.sendForm(data)
    console.log(res)
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-08-05
@vabka

You can use, for example use-fetch

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question