UNPKG

adwaita-web

Version:

A GTK inspired toolkit designed to build awesome web apps

17 lines (16 loc) 482 B
import React from "react"; function useControlled(propValue, defaultValue, setValueProp) { const [valueState, setValueState] = React.useState(propValue || defaultValue); const setValue = React.useCallback((newValue) => { if (setValueProp) setValueProp(newValue); setValueState(newValue); }, []); if (propValue !== void 0 && propValue !== valueState) { setValueState(propValue); } return [valueState, setValue]; } export { useControlled as default };