Last active
July 22, 2020 15:40
-
-
Save mekwall/368c01fd1241c664a1146252ae3cabac to your computer and use it in GitHub Desktop.
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 { 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