V
V
Vadim Stepanenko2021-03-17 22:26:22
React
Vadim Stepanenko, 2021-03-17 22:26:22

Do I need to use useEffect?

There is a project on react + redux.

And there is such a component (conditionally):

const Component = () => {
    const dispatch = useDispatch();

    const onSelect = (value) => {
        dispatch(selectAction(value));
    };
    
    return (
        <select onChange={(e) => onSelect(e.target.value)}>
            <option value="1">1</option>
            <option value="2">3</option>
            <option value="3">3</option>
        </select>
    );
};


When the select changes, an action with redux-thunk is dispatched, which sends a request to the server. And in theory, this is a side effect, shouldn't the onSelect function be implemented through useEffect?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Okhotnikov, 2021-03-18
@tsepen

Don't need it, it's normal

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question