Js for save status code
Thu Jan 18 2024 08:05:14 GMT+0000 (Coordinated Universal Time)
Saved by
@KhanhDu
#javascript
import axios from "axios"; //Check this for more information
const [user, SetUser] = useState({
name = "",
username = "",
email = "",
});
const { name, username, email } = user;
const onInputChange = (e) => {
setUser({ ...user, [e.target.name]: e.target.value }); //This will append info when type
}
const onSubmit = async (e) => {
e.preventDefault(); //This will prevent showing info in url.
await axios.post("https://localhost:8080/user") //Link to backend server
//We use async and await here to guarantee get the data before submit.
};
<form onSubmit = {(e) => onSubmit(e)}>
<input
value={name}
onChange={(e) => onInputChange(e)}
/>
</form>
content_copyCOPY
https://www.youtube.com/watch?v=4LZKnegAm4g
Comments