-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstore.ts
35 lines (32 loc) · 1017 Bytes
/
store.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import {RJSFSchema} from "@rjsf/utils"
import {JSONSchema7} from "json-schema"
import {create} from "zustand"
import {samples} from "./samples"
type Sample = {
schema: JSONSchema7 | RJSFSchema
uiSchema: object
formData: object
}
export type AppState = {
schema: JSONSchema7 | RJSFSchema
uiSchema: object
formData: object
label: string
setLabel: (label: string) => void
}
export const useStore = create<AppState>((set) => ({
schema: samples.Simple.schema as JSONSchema7 | RJSFSchema,
uiSchema: samples.Simple.uiSchema,
formData: samples.Simple.formData,
label: "Simple",
setLabel: (label: string) => {
// @ts-expect-error resolve later - TS doesn't like using a string value to query an object
const sample: Sample = samples[label]
set({
label,
schema: sample.schema as JSONSchema7 | RJSFSchema,
uiSchema: sample.uiSchema as object,
formData: sample.formData as object,
})
},
}))