Created
April 2, 2022 12:47
-
-
Save antondevv/8b810c58d8f64fb541feeb13fa0839f9 to your computer and use it in GitHub Desktop.
final-code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useSelector, useDispatch } from "react-redux"; | |
import { changeUsersName } from "./redux/actions/changeUsersName"; | |
import { changeUsersAge } from "./redux/actions/changeUsersAge"; | |
import { useState } from "react"; | |
function App() { | |
const user = useSelector((state) => state.userReducer); | |
const dispatch = useDispatch(); | |
const [name, setName] = useState(user.name); | |
const [age, setAge] = useState(user.name); | |
return ( | |
<div className="App"> | |
<h1>Name: {user.name}</h1> | |
<h1>Age: {user.age}</h1> | |
<hr></hr> | |
<form | |
onSubmit={(e) => { | |
e.preventDefault(); | |
dispatch(changeUsersName(name)); | |
dispatch(changeUsersAge(age)); | |
}} | |
> | |
<input | |
onChange={(e) => setName(e.target.value)} | |
placeholder="Change name" | |
></input> | |
<input | |
onChange={(e) => setAge(e.target.value)} | |
placeholder="Change age" | |
></input> | |
<input type="submit" value="Change user details" /> | |
</form> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment