score:-2
First, you need maybe some theoretical view:
https://pusher.com/tutorials/consume-restful-api-react
https://www.robinwieruch.de/react-hooks-fetch-data
- You should firstly save data
- You save them to the state
- You display them in the part where it is rendered
To download data from api (GET)- you don't do it directly in form - you only use either ComponentDidMount or UseEffect.
componentDidMount() {
fetch(ApiURL)
.then(res => res.json())
.then(res => this.setState({ planets: res }))
.catch(() => this.setState({ hasErrors: true }));
}
useEffect(async () => {
const result = await axios(
ApiURL,
);
setData(result.data);
});
To send data to api (POST)- It's complicated - you need information about client-server communication
Straight from the React docs:
fetch('https://mywebsite.com/endpoint/', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
firstParam: 'yourValue',
secondParam: 'yourOtherValue',
})
})
score:0
It will not work like php.. you need to have something like backend (node or php to pass the data) or even some site to accept the request..
score:5
That is not possible if your React app is static(not server side rendered). When you send some POST request to your react app, nginx(or other server) will not allow that kind of action(you cannot post to static files) Even if you bypass that restriction, react script will not have any data from your POST request, because nginx will process your request and return just a html with react script to you
Source: stackoverflow.com
Related Query
- How should a django app handle a post request from a reactjs form
- how to handle a post request in next.js?
- How to Handle Post Request in Isomorphic React + React Router Application
- How to handle POST request in reactjs?
- How to send POST request to Django API from ReactJS web app?
- How to make Post Request using ReactJS
- How to fix issue while passing ReactJS state data in post request using axios?
- How to take post request by ReactJs in Ruby On Rails?
- how get id of tr and use it in post api request body in reactjs
- How to configure WebPack DevServer to handle the POST request in React JS?
- How to handle POST request from react to django?
- How to use button id dynamic in post request in reactjs
- How to resolve post request failure ReactJS and ExpressJS
- how to make post request by axios with multiple parameters in Reactjs
- How to make a rest post call from ReactJS code?
- How to do POST in FORM Submit using reactjs and pass the object value into REST service?
- ReactJS - Handle POST requests using react router dom
- how to handle network request failed error?
- How handle multiple select form in ReactJS
- How to handle checkbox checked status in reactJS
- How to have config parameter in axios post request with headers required
- ReactJS How To Set Cookie From Fetch Request to Back End
- How to send POST data to flask using Reactjs fetch
- How to do render only after http request completed in ReactJS
- React Hooks: How to make a POST request to server
- How to use Promise.all to handle thousands of request
- How to handle window object on nodejs for server-side rendering of reactjs application
- reactjs - interrupting a post request in superagent
- Canceling my promises a POST Request through axios in Reactjs
- Reactjs - how to handle keys correctly in reused components
More Query from same tag
- How am I getting this JS error from <div> element?
- Render valid href with React passing props
- React navigation - how to nest drawerNavigator inside stackNavigator
- How can I shorten JSX code using Array methods?
- How to install only single component instead of whole package?
- How to use Leaflet.Polyline.SnakeAnim plugin in React without react-leaflet?
- Pass data across Screens
- JS loop for with condition getting 0 on javascript
- Axios having CORS issue
- Reset store after logout with Apollo client
- Store value from object with key starting with same character
- How set cards in a row using react bootstrap
- React - Date input value not updated to state
- Argument of type 'string' is not assignable to parameter of type... (React Hook Form) (TypeScript)
- How to make a reset password system in React + Firebase
- React: Unable to use useContext hook
- How can I filter an array based on a category in react?
- How to dynamically load the material-ci-icons icon
- How can I hide the code from Chrome dev tools source?
- React - how can I get updated data to show in my table?
- Running a child component with a function in parent component
- Do closures work the same way on class methods?
- React Hooks trying to useState in array ref
- React testing onSubmit using axios
- Why is my hook variable in React not holding the state I set it to?
- velocity-react - animating scrollTop after component update
- How to reload a specific tag in reactJS
- How do I set state of sibling components easily in React?
- useState in useEffect does not update state
- Creating a component from all components in a namespace