({ children }: { children: ReactNode })
| 7 | const JsonSchemaContext = createContext<Schema | undefined>(undefined); |
| 8 | |
| 9 | export function JsonSchemaProvider({ children }: { children: ReactNode }) { |
| 10 | const [json] = useJson(); |
| 11 | |
| 12 | const jsonSchema = useMemo( |
| 13 | () => inferSchema(json).toJSONSchema({ includeSchema: true }), |
| 14 | [json] |
| 15 | ); |
| 16 | |
| 17 | return ( |
| 18 | <JsonSchemaContext.Provider value={jsonSchema}> |
| 19 | {children} |
| 20 | </JsonSchemaContext.Provider> |
| 21 | ); |
| 22 | } |
| 23 | |
| 24 | export function useJsonSchema(): Schema { |
| 25 | const context = useContext(JsonSchemaContext); |