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
Name | Type | Description | Default |
---|---|---|---|
ref | RefObject<any> | The ref of the field, whose value will be updated. | - |
change | () => void | The function that will be triggered on the onChange event from the field. | - |
Return Value
Name | Type | Description |
---|---|---|
emulate | (value: any) => void | The value that will be set to the input. |