Open Pioneer Trails Packages
    Preparing search index...

    Variable useCustomFormContextConst

    useCustomFormContext: () => CustomFormContext = useCustomFormContextImpl

    React hook for accessing the property form context within a custom form.

    Provides access to the CustomFormContext instance, which contains the current feature being edited and methods to read and update its properties. This hook must be called from within a component that is rendered inside a custom property form (see DynamicFormTemplate).

    The context also allows controlling the form's validity by setting the isValid property, which determines whether the save button is enabled.

    Type Declaration

    Error if called outside of a custom property form context (e.g., when no feature is being edited).

    import { useReactiveSnapshot, DISPATCH_SYNC } from "@open-pioneer/reactivity";

    function CustomForm() {
    const context = useCustomFormContext();
    const name = useReactiveSnapshot(
    () => (context.properties.get("name") as string) ?? "",
    [context],
    DISPATCH_SYNC
    );

    useEffect(() => {
    context.isValid = name.length >= 1;
    }, [context, name]);

    return <Input value={name} onChange={(e) => context.properties.set("name", e.target.value)} />;
    }