Skip to content

Commit 609599f

Browse files
committed
feat: context reference
1 parent 9802c1e commit 609599f

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

docs/pages/reference/core/createFrames.mdx

+68
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,71 @@ handleRequest(new Request("/")).then((res) => {
146146
return res.text();
147147
});
148148
```
149+
150+
## Context
151+
152+
Core middleware is included and executed by default and gives you access to the following default context in your frame handlers:
153+
154+
### `basePath`
155+
156+
- Type: `string`
157+
158+
Specifies the base path for all relative URLs in the frame definition.
159+
160+
### `initialState`
161+
162+
- Type: generic
163+
164+
A JSON serializable value that is used if no state is provided in the message or you are on the initial frame.
165+
166+
### `request`
167+
168+
- Type: [Web API `Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
169+
170+
The request object that was passed to the request handler.
171+
172+
### `url`
173+
174+
- Type: [Web API `URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL)
175+
176+
The URL object that was parsed from the request.
177+
178+
### `searchParams`
179+
180+
- Type: `Record<string, string>`
181+
182+
The search params in the URL as an object. If there are no search params, it will be an empty object.
183+
184+
### `pressedButton`
185+
186+
- Type: `undefined | { action: "post" | "post_redirect"; index: 1 | 2 | 3 | 4 }`
187+
188+
The button that was clicked on the previous frame.
189+
190+
### `buttonIndex`
191+
192+
- Type: `number`
193+
194+
The index of the button that was clicked on the previous frame.
195+
196+
### `message`
197+
198+
- Type: `FrameMessage`
199+
200+
The frame message that was parsed from the request body.
201+
202+
### `clientProtocol`
203+
204+
- Type: `ClientProtocolId`
205+
206+
The client protocol that was used to send the frame message.
207+
208+
### `state`
209+
210+
- Type: `JsonValue`
211+
212+
The state extracted from the frame message. If you are on the initial frame (no button pressed), the value is the `initialState` value passed to `createFrames`. If you are on a frame with a button pressed, the value is the state from the previous frame.
213+
214+
215+
216+

0 commit comments

Comments
 (0)