@react-md/form
Version:
This package is for creating all the different form input types.
33 lines • 1.17 kB
JavaScript
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
import { useCallback, useState } from "react";
/**
* This is a simple hook that will allow you to "strongly" type a `Select`
* component's value since the `onChange` handler only returns a `string`.
*
* @param defaultValue - The default value to use
* @returns an ordered list containing the current value followed by the
* dispatch function to update the state.
*/
export function useSelectState(defaultValue) {
var _a = __read(useState(defaultValue), 2), value = _a[0], setValue = _a[1];
var setTypedValue = useCallback(function (nextValue) {
setValue(nextValue);
}, []);
return [value, setTypedValue];
}
//# sourceMappingURL=useSelectState.js.map