import React, { createContext, useEffect } from 'react';
const initialContext = {
    field: undefined,
    path: '',
    schemaPath: '',
};
export const FieldContext = createContext(initialContext);
export const FieldProvider = ({ children, context, }) => {
    const [field, setField] = React.useState();
    const [path, setPath] = React.useState();
    const [schemaPath, setSchemaPath] = React.useState();
    useEffect(() => {
        const nextSchemaPath = String(context.schemaPath ?? '');
        if (schemaPath !== nextSchemaPath) {
            setField(context.field);
            setPath(context.path);
            setSchemaPath(nextSchemaPath);
        }
    }, [schemaPath, context]);
    return (<FieldContext.Provider value={{
            field,
            path,
            schemaPath,
        }}>
      {children}
    </FieldContext.Provider>);
};
