From c9ce16ed5fb12ed6ee3c9cdd6a939033384b9315 Mon Sep 17 00:00:00 2001 From: Girish21 Date: Sun, 12 Jun 2022 00:31:15 +0530 Subject: [PATCH] readme add note about cf env types for kv --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index b45bc5a..9b5ee73 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,22 @@ kv_namespaces = [ **Note**: We need to add the `preview_id` key to the configuration file along with the `id` key with the same value. +The bounded KV will be available in the `loader`/`action` via the `context` argument passed to the functions. We define types for the `context` at [cloudflare-env](./config/cloudflare-env/index.d.ts). To add types for a newly bounded KV, we just have to add the following to the `.d.ts` file + +```ts +MY_KV: KVNamespace +``` + +Now we can access the KV namespace from the data function through the `context`. + +```ts +export let loader: LoaderFunction = ({ context }) => { + context.MY_KV + // ^ Will have proper type definitions + return null +} +``` + ## Turbo Setup ✨ This repository is used in the `npx create-turbo@latest` command and selected when choosing which package manager you wish to use with your monorepo (npm).