You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Frames.js is the react based framework for making frames. Debugger included."
4
+
---
5
+
6
+
# Guide: State Management in Frames.js
7
+
8
+
State in Frames.js is a way for you to store data that you want to use in between frames requests. The frames spec allows up to 4kb of data to be stored in the state object.
9
+
10
+
## Setup
11
+
12
+
To use state in frames.js, you should declare the initial state in your `createFrames` call. If your state type is not declared explicitly it will be derived from the initial state.
13
+
14
+
```ts [frames.ts]
15
+
import { createFrames } from"@framesjs/next";
16
+
17
+
exporttypeState= {
18
+
count:number;
19
+
};
20
+
21
+
exportconst frames =createFrames<State>({
22
+
initialState: {
23
+
count: 0,
24
+
},
25
+
});
26
+
```
27
+
28
+
## Accessing state
29
+
30
+
You can access the state object in your frame on the `ctx` parameter. The initial frame will have the state object with the initial values.
To update the state, you just include the updated state object in your handler's [`FrameDefinition`](/reference/core/createFrames#framedefinition) return value.
0 commit comments