UNPKG

@react-md/form

Version:

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

39 lines 1.38 kB
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 hook can be used to control the state of a radio group or a select * element. * * @param defaultValue - The default value. If you want the user to specifically * choose a value, set this to the empty string. * @param onChange - An optional change event handler to also call when the * change event is triggered. * @returns a list containing the current value, a change event handler, and * then a manual value setter. */ export function useChoice(defaultValue, onChange) { var _a = __read(useState(defaultValue), 2), value = _a[0], setValue = _a[1]; var handleChange = useCallback(function (event) { if (onChange) { onChange(event); } setValue(event.currentTarget.value); }, [onChange]); return [value, handleChange, setValue]; } //# sourceMappingURL=useChoice.js.map