You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

23 lines
618 B

import { Dispatch, useReducer } from 'react';
import { createContainer } from 'react-tracked';
import { SchemaState, SchemaAction } from '../model';
import reducer from '../reducer/schema';
interface StoreProps {
initialData: SchemaState;
}
const defaultData: SchemaState = {
type: 'object',
properties: {},
required: [],
};
const useValue = ({ initialData }: StoreProps): [SchemaState, Dispatch<SchemaAction>] =>
useReducer(reducer, initialData || defaultData);
export const {
Provider: SchemaProvider,
useTrackedState: useSchemaState,
useUpdate: useSchemaDispatch,
} = createContainer(useValue);