-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a more relevant react example using react-query #270
Comments
@kasperpeulen a match, by default, throws an exception when the What about your examples is more up to date than the ones in the readme? |
I think it is worth to update the example, currently the example uses render function approach and from first glance it is not clear that you can use |
code alternative not using this proposal should also be added for comparison export function Todos() {
const todos = useTodosQuery();
if (todos.status === 'loading') {
return <div>Loading</div>;
}
if (todos.status === 'error') {
return <span>Error: {todos.error.status}</span>;
}
return (
<div>
<div>
{todos.map((todo) => (
<p key={todo.id}>{todo.title}</p>
))}
</div>
<div>{isFetching ? 'Background Updating...' : ' '}</div>
</div>
);
} const STATES = {
loading: (todos) => <div>Loading</div>,
error: (todos) => <span>Error: {todos.error.status}</span>,
};
export function Todos() {
const todos = useTodosQuery();
return (
STATES[todos.state]?.(todos) || (
<div>
<div>
{todos.map((todo) => (
<p key={todo.id}>{todo.title}</p>
))}
</div>
<div>{isFetching ? 'Background Updating...' : ' '}</div>
</div>
)
);
} |
I stumbled upon this randomly after developing this a few weeks ago 😂 https://github.com/LivioGama/use-query-state-layout |
Would be nice to add a more up to date react example, maybe something like this:
Btw, what would happen here if the match is not exhausted? It would be awesome if TS could warn about that.
This is using react-query v4 beta:
https://codesandbox.io/s/kind-butterfly-rh2vvl?file=/src/App.tsx
The text was updated successfully, but these errors were encountered: