Created
November 12, 2020 07:10
-
-
Save guillaumewuip/97bf29c57589ccd92636316d12844977 to your computer and use it in GitHub Desktop.
State and Store in frontend codebase - State example - App
This file contains 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 * as React from "react"; | |
import { useState } from "@iadvize-oss/store-react"; | |
import * as State from "./state"; | |
import { store } from "./store"; | |
import { createUserAndSave } from "./service"; | |
import Users from "./components/Users"; | |
import UserForm from "./components/UserForm"; | |
const handleFormSubmission = createUserAndSave; | |
export default function App() { | |
const state = useState(store); | |
if (State.isLoading(state)) { | |
return <>Loading...</>; | |
} | |
if (State.isError(state)) { | |
return <>Something went wrong</>; | |
} | |
return ( | |
<> | |
<Users users={State.users(state)} /> | |
<UserForm onSubmit={handleFormSubmission} /> | |
</> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment