Function useValue

  • Similar to React's useState hook. Returns a Value and a Setter as an array of two items. Value will be undefined if the Resource isn't loaded yet. The generated Setter function can be called to set the value. Be sure to look at the various options for useValueOptions (debounce, commits, error handling).

    // Simple usage:
    const resource = useResource('https://atomicdata.dev/classes/Agent');
    const [shortname, setShortname] = useValue(
    'https://atomicdata.dev/properties/shortname',
    resource,
    );
    // With options:
    const resource = useResource('https://atomicdata.dev/classes/Agent');
    const [error, setError] = useState(null);
    const [shortname, setShortname] = useValue(
    'https://atomicdata.dev/properties/shortname',
    resource,
    {
    commit: true,
    validate: true,
    commitDebounce: 500,
    handleValidationError: setError,
    },
    );

    Parameters

    • resource: Resource
    • propertyURL: string
    • opts: useValueOptions = {}

      Saves the resource when the resource is changed, after 100ms

    Returns [JSONValue | undefined, setValue]

Generated using TypeDoc