score:3

Accepted answer

In your example, setSelectedIDs not updating application state.

That's because you set the same reference, you should make a copy:

setSelectedIDs(new Set(set));

codesandbox example.


What would happen if we returned at the ??? line

Nothing would happen, you just changed a variable in your function, you can do it as many times you like.

When you want your React-App to notice the change, you should then call a function the updates the state (setSelectedIDs()) and your app will be rerendered.

Refer to Using State Correctly


Related Query

More Query from same tag