Answer the question
In order to leave comments, you need to log in
How to immediately return a new state from useState after a change?
Hello everyone reading this question!
There is a selector whose value works as a filter:
const { Option } = Select;
const dispatch = useDispatch();
const [filters, setFilters] = useState({status: null});
<Select
style={{ width: 100 }}
placeholder="Статус"
optionFilterProp="children"
onChange={onChangeStatus}>
<Option value="created">Создан</Option>
<Option value="added">Добавлен</Option>
<Option value="photo">Фотография продукта</Option>
</Select>
function onChangeStatus(value) {
setFilters({ status: value})
dispatch(getFilters(filters));
}
function onChangeStatus (value) {
setFilters({
...filters, status: value
}, () => {
dispatch(getFilters(filters));
});
}
Answer the question
In order to leave comments, you need to log in
And why not pass { status: value } to `getFilters` immediately, to which we have access in the function?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question