To use react-query
to make a POST
request with JSON
data to an API, follow these steps:
react-query
using npm or yarn:index.ts24 chars2 lines
or
index.ts21 chars2 lines
POST
request:index.ts431 chars23 lines
useMutation
hook to call the postData
function and pass the JSON
data:index.ts781 chars31 lines
This code will create a form with two inputs for name
and age
, and a button to submit the data. When the button is clicked, postMutation
will be called with the JSON
data, and React Query will handle the network request and update the status
accordingly.
Note: This code assumes that react-query
and react
are already imported and set up in the project.
gistlibby LogSnag