Home > Blockchain >  How to connect textarea with the post request in react?
How to connect textarea with the post request in react?

Time:11-30

enter image description here* Hello i'm quite new to programming! How can i connect the textarea to my post request so i can change the values and send it the json data ? *

CodePudding user response:

hi in the textarea add the following

  <textarea
    value={state}
    onChange={e=> setState(e.target.value)} ...restOfProps>
....
  </textarea>

this is to update the state so you can use the fetch

and move the fetch outside the useeffect make the function as async as then call it in useEffect because fetch is better to be async. and I think you dont need the form really for one field

CodePudding user response:

first move the fetch outside the useEffect in a separate function and the call it on send

create a state like const [data,setData] = useState({})

add onChange event on textArea and inside it assign its value to state variable

assign this state variable to post request body and on press send button call this function

  • Related