Skip to content

Commit

Permalink
docs: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericoo committed Sep 16, 2023
1 parent d68702a commit 2ed5cd9
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,29 @@ const loader = makeLoader(async () => {
});
});

> **Note**
> You will have to `await` swr so that the ui-blocking part can be resolved (the cache) prior to rendering, but the fresh data will still be sent as an unfulfilled promise.

See the full example [here](/examples/vite-react).

// automatically handles cached data, loading states, and errors, obeys `onError` behaviour
const Component = () => {
const { posts } = useLoaderData<typeof loader>();
const { posts } = useLoaderData<typeof loader>();

return <SWR
data={posts}
// will render when there is no cache and no data laoded yet
loadingElement={<PostsSkeleton/>}
// will render if there’s an error loading the data and there is no cache
errorElement={<ErrorView heading="Error loading matches" />}
>
{posts => <ul>{posts.map(posts => <li key={post.id}>{post.title}</li>)}</ul>}
>
{posts => <ul>{posts.map(posts => <li key={post.id}>{post.title}</li>)}</ul>}
</SWR>

}

```

> **Note**
> You will have to `await` swr so that the ui-blocking part can be resolved (the cache) prior to rendering, but the fresh data will still be sent as an unfulfilled promise.
See the full example [here](/examples/vite-react).

### Invalidating the cache

You can use invalidation as part of actions or simply call it in your event handlers, if your app is not server-side rendered.
Expand Down

0 comments on commit 2ed5cd9

Please sign in to comment.