Skip to content

Instantly share code, notes, and snippets.

@guillaumewuip
Created November 12, 2020 07:10
Show Gist options
  • Save guillaumewuip/97bf29c57589ccd92636316d12844977 to your computer and use it in GitHub Desktop.
Save guillaumewuip/97bf29c57589ccd92636316d12844977 to your computer and use it in GitHub Desktop.
State and Store in frontend codebase - State example - App
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