Skip to content

Instantly share code, notes, and snippets.

@carpben
Created March 11, 2022 04:18
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 carpben/58dfc8a7ff39077e36b1b4142af6d84a to your computer and use it in GitHub Desktop.
Save carpben/58dfc8a7ff39077e36b1b4142af6d84a to your computer and use it in GitHub Desktop.
function requestTodos() {
return axios.get("/todos"); // or a different request function that throws on an error
}
// A query provider is a
function Todos() {
const { data, status, error } = useQuery("todos", requestTodos);
if (status === "loading") {
return <span>Loading...</span>;
}
if (status === "error") {
return <span>Error: {error.message}</span>;
}
return (
<div className="list-wrapper">
{data.map((todo) => (
<Todo todo={todo} />
))}
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment