Redux vs Mobx
Paolo Mosca
tw: @paolomoscaBCN
Startup Advisor
Business & Tech
Passionate in Mobile
Inline Skater
bla bla bla
Applications aggregate Components
Components have internal state accessible with this.state and setState(...)
Inside a component everything works fine
Connection between components can be complex
Sharing or mutating state between components
Uneeded 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);
resources related:
Redux or MobX: An attempt to dissolve the Confusion
http://bit.ly/2q88UkR
contact me: info@paomosca.com