0

I have used this website to get the logic for a useFetch hook. All I am trying to do is to send a post request and then map the request into a type. I know this will be a simple answer but can't seem to find anything online! Please view the link above for the useFetch hook! :)

EDIT: The body is empty as this is just an example

Error: View screenshot of error

Component:

const requestOptions = {
  method: 'POST',
  headers: {},
  body: JSON.stringify({}),
};
const { data, error } = useFetch<ExampleType>({url, requestOptions});
9
  • Are there are errors? Commented Oct 21, 2021 at 9:31
  • have you seen this post ? Commented Oct 21, 2021 at 9:35
  • @Papa yeah let me add them here Commented Oct 21, 2021 at 9:35
  • @JakubLicznerski that is a get request? No body sent too? Commented Oct 21, 2021 at 9:37
  • I believe you can pass same options to the generic useFetch that is described there Commented Oct 21, 2021 at 9:41

1 Answer 1

1

UseFetch Documentation says you need to pass in a string as the first argument so call the hook with

useFetch<ExampleType>(url, requestOptions);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.