score:0
remove matches
from your default state declaration, then, in your condition try something like this :
if(true /** your condition */) {
setformdata({
...formdata, /** current data*/
matches:[] /** add your key matches with correct array value.*/
})
}
i guess probably something like this ? :
if(matchsarray && array.isarray(matchsarray) && matchsarray.length > 0) {
setformdata({
...formdata, /** current data*/
matches:matchsarray /** add your key matches with correct array value.*/
})
}
don't forget to put your data state in a real formdata to build your post request after. like :
const finalformdata = new formdata()
finalformdata.append(
'data', /** your key catch by your backend api*/
formdata /** the react state*/
)
let me know if it's help you. :)
score:1
you can write the sending part inside a useeffect.
useeffect(
() => {
yourvariable && sendingfucntion();
},
[yourvariable]
)
Source: stackoverflow.com
Related Query
- How to send data only if a variable is true?
- How can I display only the data where the field is true
- React onClick method sets variable to true but only for a second when the page reloads - how to make changes permanent?
- How to add css propety only variable is. true ? React
- how can i send an api call from the supreme function to another component called product to change a mock data called cart: true and display in cart
- How to open a page in new tab on click of a button in react? I want to send some data to that page also
- ReactJS: how to call useEffect hook only once to fetch API data
- How to fetch data only once in a Next.js app and make it accesible to all the app, both in server and client
- How do I send custom data in react-router goBack method like push and replace methods?
- How to send body data and headers with axios get request?
- How to send form data from React to express
- How to send and receive large JSON data
- How to send POST data to flask using Reactjs fetch
- How to send data from dialog back to parent container with react?
- How to fetch data only when the modal loads
- How to send props to a variable on the basis of system wide theme in javascript?
- How to fetch data with multiple requests in Redux action creator and then send collected data to reducer?
- How to send data from stateless child component to stateless parent component in react?
- How to fetch data only once and never again in reacthooks and redux
- Send a prop only if condition is true in react.js
- How to trigger useEffect in React only once AFTER some certain variable gets loaded
- NextJS: How to send data from one page to another page's getInitialProps function
- React.js Chrome Extension - How to store data from Background.js in a variable inside React?
- How to send data from express server to client on Next js?
- How to send data from react and use the request body in express, using Axios?
- How would I only show data when searched in input?
- How do I send data from React to Node server and back result to React?
- How to load initial data in Flux, but only if a component needs it
- How to pass a variable data to createFragementContainer
- How to send from node data to localStorage React?
More Query from same tag
- Using useEffect to trigger a re-render by updating state, but cannot have state in dependency array?
- How can the render be synced with the state on pagination click with react?
- How can I return a file using react? Or `npm unload` analogs for express
- React won't render my newly created component accessed via route
- React Lifecycles managing intervals with changing values
- React native web issue with react native vector icons in storybook
- Promise.all Not Loading Images in React For Use In HTML Canvas
- Reusing the same function with different content
- Pushing Data Into My Redux State
- Overlay transparent circle on webcam preview in a browser
- ReactJS => local image not loading
- React: 2 way binding props
- Create an axios post with multiple inputs using React Hooks
- Issues with controlled components (checkboxes) and RESTful mock in simple react app?
- How do I set a ref when using react.createElement?
- How to show ISO date format in a date input field - React
- Unable to access/manipulate data from weather API using axios with useEffect in React.js
- React: How to capture focus when a focused child component unmounts
- How to test changes made by onClick event that calls a setState function, which is passed from another component and changes UI?
- render component conditionally
- function gives me TypeError: Cannot read property 'resize' of undefined
- Picking correct enum type to access object nested property
- Convert dataURL/Buffer to blob
- Flatten an object of child arrays
- Conversion from React Router V2.x to V4.x
- ReactJs display data in optgroup
- How to format custom date,day in moment.js?
- Megre results of one API call with another React.js Javascript
- Array.prototype.filter() expects a value to be returned at the end of arrow function
- Using switch statement with dynamic components in NextJS