Created
November 12, 2020 06:57
-
-
Save guillaumewuip/1c8bb5f757bf48250df7cf1054ef6cac to your computer and use it in GitHub Desktop.
State and Store in frontend codebases - Redux example - App
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 React from "react"; | |
import { useDispatch, useSelector } from "react-redux"; | |
import { getUsers } from "./selectors"; | |
import { createUser } from "./actionCreators"; | |
import Users from "./components/Users"; | |
import UserForm from "./components/UserForm"; | |
export default function App() { | |
const dispatch = useDispatch(); | |
const users = useSelector(getUsers); | |
console.log({ users }); | |
const handleFormSubmission = ({ firstName, lastName, picture }) => { | |
if (firstName && lastName) { | |
dispatch(createUser(firstName, lastName, picture)); | |
} | |
}; | |
return ( | |
<> | |
<Users users={users} /> | |
<UserForm onSubmit={handleFormSubmission} /> | |
</> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment