Redux vs Mobx
En las aplicaciones agregamos Componentes
Cada componente tiene su estado interno accesible con this.state y setState(...)
Internamente al componente - funciona
La conexión entre componentes se complica
Compartir o mutar un estado entre componentes
Evitar re-render
Comparison (pros and cons are relatives)
Redux over Mobx
Mobx over Redux
You can always refactor from MobX to redux if needed
(why MobX?)
Start with Mobx
Go strict
React-Native
An app is a small project for definition.
If is not, maybe you're over-engineering.
const initialState = {
users: [
{
name: 'Paolo'
},
{
name: 'Dan'
}
]
};
// reducer
function users(state = initialState, action) {
switch (action.type) {
case 'USER_ADD':
return { ...state, users: [ ...state.users, action.user ] };
default:
return state;
}
}
// action
{ type: 'USER_ADD', user: user };
// somewhere in the app ...
dispatch({ type: 'USER_ADD', user: user });
class UserStore {
@observable users = [
{
name: 'Paolo'
},
{
name: 'Dan'
}
];
// if you want to go strict using @action
@action addUser = (user) => {
this.users.push(user);
}
}
//somewhere in the app
userStore.users.push(user);
// strict case
userStore.addUser(user);