score:0
you don't necessarily need useeffect here.
here is how you can implement such thing:
declare a state to hold form values:
const [formdata, setformdata] = usestate({})
declare function to set the state:
const handlechange = (name, value) => {
setformdata({...formdata, [name]: value})
}
input onchange to capture:
// handlechange has two parameters
<input
type="text"
placeholder="first name"
name="firstname"
id='firstname'
value={props.data.firstname}
onchange={(event) => handlechange('firstname', event.target.value)}
/>
function for calling post axios post request
const handlesubmit = () => {
//check for validations code here
// if validations are right then post request here
// this will give you all the fields like firstname: "", lastname: ""
let requestbody = {
...formdata
}
axios.post("url", requestbody).then((res)=> {
//your code here
})
}
Source: stackoverflow.com
Related Query
- where to call the Axios post request in reactjs
- ReactJS axios POST call to PHP - Request Aborted error
- Canceling my promises a POST Request through axios in Reactjs
- $_FILES is empty when sending a POST request using axios in ReactJs
- Need to override the default time out of Axios post request
- React axios post request does not send the data
- Input undefined when sending post request to the nodejs api using react and axios
- Create an Axios post to send an uploaded file using Dropzone for a Scala function to handle the respective request
- Why is my axios post request not sending data? I'm getting a response that means the fields are empty
- Problem with sending a POST request with axios in reactjs
- Make Multiple Post Requests In Axios then get all the response to make another request
- Is it okay to call another endpoint inside the then() function? ReactJS Axios
- axios post request to send form data in reactjs
- I need to call the page render after POST request
- Making a POST call using Fetch in ReactJS (With header and Request Body)
- Reactjs POST request through axios
- 'Access-Control-Allow-Credentials' header in the response is ' ' when trying to send a POST request to an API using Axios
- data is not inserted in the payload while making a POST request in reactjs
- How to send request payload as optional to the api call in React JS Axios
- Nested axios api request / call not rendering in child component reactjs
- How to print the result from an axios post request
- Post multiple Request to REST API django from Array using Axios in Reactjs
- having difficult in debugging some functions where the author mainly did axios request
- How to use Axios to do a 2nd API get request call after componentDidMount, once the user interacts with your App?
- Axios ReactJs Laravel: How to retrieve the multiple request Api
- Laravel React API returns 404(Not Found) when sending axios post request even though the route is present in api.php
- update the state of my component with the response data after Post request with axios
- How to pass Token of the first request response to the second request header, using Axios in an Ionic React app (2 Post Requests)
- ReactJS axios POST request send all options as a single JSON key with empty value
- Axios post request is processed twice by the node server
More Query from same tag
- How to set the reference to the 'leafletElement' using Typescript inside react-leaflet?
- How to use a function from another file in Main App function?
- How to insert data with post using react redux?
- How do I send multiple form inputs in a post request react
- Slideshow effect with Framer Motion
- Passing props to children components with react-router v4
- Table iteration in React conditional rendering
- How to override Drawer in Material UI
- React Error: Cannot read property 'map' of undefined
- Is that possible to dispatch stateful component state to redux store
- render Multidimensional array react js
- Show dynamically added row in expanded form in ant tables
- Not able to get the value after updating the state
- how to apply the some array method to a filter search in react
- My image doesn't render when I pass the image source path as a props. Image renders when I give the image source path
- Mock inner axios.create()
- JS: Converting dictionary to a list of dictionaries
- Runtime error when trying to implement client-only routes in GatsbyJS
- How to make infinite scroll work with react and intersection api while lazily fetching data?
- OnChange function doesn't trigger when change occurs
- React app freezing when setInterval is called
- Material-ui Grid Responsive Direction Column Width doesn't work
- Certain parameters returns function error using reactjs
- change content if update is made in react?
- Table inside other table row in ReactJS
- How do I map for every two elements for react?
- User role based routes
- React with Google Maps Api, how to recenter map
- How to work with conditional dynamically import in react
- How to set initial state with using ES6 class in React?