Skip to content

Instantly share code, notes, and snippets.

@mekwall
Last active July 22, 2020 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mekwall/368c01fd1241c664a1146252ae3cabac to your computer and use it in GitHub Desktop.
Save mekwall/368c01fd1241c664a1146252ae3cabac to your computer and use it in GitHub Desktop.
import React from "react";
import { useStores } from "@app/stores";
import { TodoItem } from "@app/components";
export const TodoList = () => {
const { todoStore } = useStores();
// This call will trigger a fetch automatically if we don't have any data
const containers = todoStore.getAll();
if (!todoStore.isReady) {
// Handle setup state
return;
}
if (todoStore.isPending) {
// Handle loading state
return;
}
if (!todoStore.inFailstate) {
// Handle error
return;
}
// Each container has isReady, isPending and inFailstate as well
// so you can handle them individually if you need to
const todos = containers.map((c) => c.value);
return (
<div>
{todos.map((todo) => <TodoItem key={todo.id} todo={todo} />)}
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment