I wanted to know how to gather the values of my inputs and save them in a state to make a post on a server. Thank you!
CodePudding user response:
First off, welcome to stackoverflow!
This is kind of big question asking many separate things, almost as big a question as "make my app for me". That kind of question isn't what stackoverflow is for and generally won't get answered, at least not how you'd like.
Here are some resources for learning though.
Forms with React (Follow and you'll understand how to set the form values to state): https://reactjs.org/docs/forms.html
React Events (Follow and you'll understand how to make something happen, ie ajax request, in response to a click or form submission): https://reactjs.org/docs/handling-events.html
Using the Fetch Api (follow and you'll know how to make an ajax request): https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
Fetching Data with React (follow and you'll have some options for making ajax requests within a react app): https://www.freecodecamp.org/news/fetch-data-react/
Also check out How to Ask a Good Question on Stackoverflow: https://stackoverflow.com/help/how-to-ask
I'd definition suggest going through ALL the react documentation as well, it really isn't a lot to read and can't be skipped IMO.
Good luck!
CodePudding user response:
if you familiar with hooks, there is a hook named useState
if you know how to use, it will be easy for you.
suppose, you want to save email in local state.
import {useState } from "react";
**in your functional component **
const [userEmail, setUserEmail] = useState('')
**in your input element **
<input
.......
value={userEmail}
onChange={(e)=>setUserEmail(e.target.value)} />
this input value will save to userEmail
in local state