import Input from "@/components/generics/input/Input"; import "./AbbreviationsBlock.scss"; import { AbbreviationsBlockProps } from "./AbbreviationBlock.interface"; import { useEffect, useMemo, useState } from "react"; import { useAppDispatch, useAppSelector } from "@/store/hooks"; import { setAbbreviation } from "@/shared/hooks/useAbbreviations/reducer"; export const AbbreviationsBlock = ({ abbreviation, values }: AbbreviationsBlockProps) => { const { abbreviations } = useAppSelector((state) => state.request); const storedValue = useMemo(() => abbreviations.find((e) => e.key === abbreviation), [abbreviations, abbreviation]); const [selectedOption, setSelectedOption] = useState(storedValue?.value ?? values[0]); const dispatch = useAppDispatch(); useEffect(() => { dispatch(setAbbreviation({ key: abbreviation, value: selectedOption })); }, [abbreviation, dispatch, selectedOption]); return (
Сокращение {abbreviation} :
{values.map((value, index) => (
setSelectedOption(value)}>
{value}
{}} checked={selectedOption === value} />
))}
); };