Develop ultra fast with Prismane 🎉

useEmulatedFieldChange

useEmulatedFieldChange hook provides a simple way to emulate field change events.

Import

import { useEmulatedFieldChange } from "@prismane/core/hooks";

Usage

function Demo() {
  const [value, setValue] = useState("");

  const ref = useRef(null);

  const handleChange = (e) => setValue(e.target.value);

  const emulate = useEmulatedFieldChange(ref, handleChange);

  return (
    <Stack>
      <Field
        value={value}
        onChange={handleChange}
        placeholder="Emulated Value"
        ref={ref}
      />
      <Button onClick={() => emulate("Custom Value")}>
        Emulate Custom Change Event
      </Button>
    </Stack>
  );
}

API

Parameters

NameTypeDescriptionDefault
refRefObject<any>The ref of the field, whose value will be updated.-
change() => voidThe function that will be triggered on the onChange event from the field.-

Return Value

NameTypeDescription
emulate(value: any) => voidThe value that will be set to the input.