const options : IOption[] = [
{ value: "asc", label: "Price: Low to High" },
{ value: "desc", label: "Price: High to low" },
];
const [currentSort, setCurrentSort] = useState("asc");
const getValue = () => {
return currentSort ? options.find((c) => c.value === currentSort) : "";
};
const onChange = (newValue: SingleValue<string | IOption>) => {
console.log((newValue as IOption).value); `//Тут выводится новое значение которые я выбрал в списке`
setCurrentSort((newValue as IOption).value);
console.log(currentSort); `//а тут несмотря на изменения стейта выводится старое значение`
dispatch(sortProducts(currentSort));
};
return (
<div class="app">
<Select onChange={onChange} value={getValue()} options={options} />
</div>
)