Skip to content
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

docs(guides/data-loading): add Cloudflare Pages reference to Cloudflare KV section #3718

Merged
merged 8 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@
- vkrol
- vlindhol
- vmosyaykin
- vorcigernix
- weavdale
- wKovacs64
- wladiston
Expand Down
34 changes: 33 additions & 1 deletion docs/guides/data-loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,40 @@ export default function Product() {
```

## Cloudflare KV
If you picked Cloudflare Pages as your environment, [Cloudflare Key Value][cloudflare-kv] storage allows you to persist data at the edge as if it were a static resource. To start with local development, you need to add a ```--kv``` parameter with a name of your namespace to the package.json task, so it would look like this:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you picked Cloudflare Pages as your environment, [Cloudflare Key Value][cloudflare-kv] storage allows you to persist data at the edge as if it were a static resource. To start with local development, you need to add a ```--kv``` parameter with a name of your namespace to the package.json task, so it would look like this:
If you picked Cloudflare Pages as your environment, [Cloudflare Key Value][cloudflare-kv] storage allows you to persist data at the edge as if it were a static resource. To start with local development, you need to add a `--kv` parameter with a name of your namespace to the package.json task, so it would look like this:


If you picked Cloudflare Workers as your environment, [Cloudflare Key Value][cloudflare-kv] storage allows you to persist data at the edge as if it were a static resource. You'll need to [do some configuration][cloudflare-kv-setup] but then you can access the data from your loaders:
```"dev:wrangler": "cross-env NODE_ENV=development wrangler pages dev ./public --kv PRODUCTS_KV"```
vorcigernix marked this conversation as resolved.
Show resolved Hide resolved

This enable you to use the PRODUCTS_KV in a loader context:
vorcigernix marked this conversation as resolved.
Show resolved Hide resolved
```tsx
import type { LoaderFunction } from "@remix-run/cloudflare"; // or "@remix-run/node"
import { json } from "@remix-run/cloudflare"; // or "@remix-run/node"
import { useLoaderData } from "@remix-run/react";

export const loader: LoaderFunction = async ({
context, params,
}) => {
return json(
await PRODUCTS_KV.get(`product-${params.productId}`, {
type: "json",
})
);
};

export default function Product() {
const product = useLoaderData();
return (
<div>
<p>{} Products</p>
{/* ... */}
</div>
);
vorcigernix marked this conversation as resolved.
Show resolved Hide resolved
}
```



For Cloudflare Workers environment you'll need to [do some configuration][cloudflare-kv-setup] but then you can access the data from your loaders:

```tsx filename=app/routes/products/$productId.tsx
import type { LoaderFunction } from "@remix-run/node"; // or "@remix-run/cloudflare"
Expand Down