UNPKG

@navikt/ds-react

Version:

React components from the Norwegian Labour and Welfare Administration.

25 lines 747 B
import { useEffect, useState } from "react"; import { useControllableState } from "../util/hooks/useControllableState.js"; export function useToggleGroup({ onChange, value, defaultValue = "", }) { const [focusedValue, setFocusedValue] = useState(defaultValue); const [selectedValue, setSelectedValue] = useControllableState({ defaultValue, value, onChange, }); /** * Sync focused `value` with controlled `selectedValue` */ useEffect(() => { if (value != null) { setFocusedValue(value); } }, [value]); return { selectedValue, setSelectedValue, focusedValue, setFocusedValue, }; } //# sourceMappingURL=useToggleGroup.js.map