React have State property like Vue.set. it just re-renders the component and using observable technology(diff algorithm) and update only changed element instead of whole DOM update...


React doesn't have Vue's reactivity features and doesn't detect deep changes in state object.

React solely relies on state immutability, i.e. a state is expected to be a new object after it's updated.

In Vue:

Vue.set(, 'bar', 1);

Correct way in React:

// just setState for useState hook
this.setState(state => ({
  foo: {,
    bar: 1

Incorrect way in React: = 1;
this.setState(this.state); // or this.forceUpdate();

This will update the component but may not work as expected in child components that rely on immutable state. This won't work with useState hook because it relies on immutable state.

Third-party libraries can be used to make the immutability of React state easier (Immer), or even replace it with mutable state (MobX). MobX works similarly to Vue reactivity (descriptor getter/setter in Vue 2, Proxy in Vue 3).

Related Query

More Query from same tag