UNPKG

@favdevs/payload-ai

Version:

<p align="center"> <img alt="Payload AI Plugin" src="assets/payload-ai-intro.gif" width="100%" /> </p>

34 lines (33 loc) 1 kB
import { jsx as _jsx } from "react/jsx-runtime"; import React, { createContext, useEffect } from 'react'; const initialContext = { field: undefined, path: '', schemaPath: '' }; export const FieldContext = /*#__PURE__*/ 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 /*#__PURE__*/ _jsx(FieldContext.Provider, { value: { field, path, schemaPath }, children: children }); }; //# sourceMappingURL=FieldProvider.js.map