Created
March 11, 2022 04:18
-
-
Save carpben/58dfc8a7ff39077e36b1b4142af6d84a to your computer and use it in GitHub Desktop.
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
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