in UI applications
one of the hardest parts of a UI application
in simple terms: it's a combination of design patterns which helps you to synchronise state across all the applications components
a typical UI application looks like this:
Is there something wrong with this?
implementations: @rxjs/Subject
implementations: eventemitter2
it's a reactivity pattern where an UI component updates based on a piece of state (or data)
global state
local state
const MyComponent = () => {
const [counter, setCounter] = useState(0);
return(<div>{counter}</div>);
}
const state = { users: [] };
// when changing state
state.users = [...state.users, newUser];
libraries in the wild:
immutablejs
why?
for components (observers) to know when to re-render. (oldStateRef !== newStateRef)