Skip to content

Instantly share code, notes, and snippets.

@guillaumewuip
Created November 12, 2020 06:57
Show Gist options
  • Save guillaumewuip/1c8bb5f757bf48250df7cf1054ef6cac to your computer and use it in GitHub Desktop.
Save guillaumewuip/1c8bb5f757bf48250df7cf1054ef6cac to your computer and use it in GitHub Desktop.
State and Store in frontend codebases - Redux example - App
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