UNPKG

@react-md/form

Version:

This package is for creating all the different form input types.

37 lines 1.32 kB
"use strict"; 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; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.useSelectState = void 0; var react_1 = require("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. */ function useSelectState(defaultValue) { var _a = __read((0, react_1.useState)(defaultValue), 2), value = _a[0], setValue = _a[1]; var setTypedValue = (0, react_1.useCallback)(function (nextValue) { setValue(nextValue); }, []); return [value, setTypedValue]; } exports.useSelectState = useSelectState; //# sourceMappingURL=useSelectState.js.map