Skip to content

Instantly share code, notes, and snippets.

View raphaelmonte's full-sized avatar

Raphael Monte raphaelmonte

  • Hotmart
  • Belo Horizonte/Minas Gerais, Brasil
View GitHub Profile
const store = createStore(combineReducers({
products: productsReducer,
...
}));
ReactDOM.render(
<Provider store={store}>
<Main />
</Provider>,
document.getElementById('root')
@raphaelmonte
raphaelmonte / save-user.thunk.js
Last active May 9, 2020 22:05
Dependency Injection with middlewares
function saveUser(user) {
// um thunk tem acesso à metodos da Store
return function(dispatch, getState) {
// ...
}
}
store.dispatch(saveUser(user));
@raphaelmonte
raphaelmonte / redux-pubsub.js
Last active October 13, 2020 11:21
Redux - Example Publish-subscribe pattern
function firstReducer(state, action) {
if (action.type === 'LOGIN_PENDING') console.log('firstReducer log');
return state;
}
function secondReducer(state, action) {
if (action.type === 'LOGIN_PENDING') console.log('secondReducer log');
return state;
}
@raphaelmonte
raphaelmonte / example-facade.jsx
Last active May 30, 2020 14:54
Redux - Facade
// index.jsx
const store = createStore(combineReducers({
products: productsReducer,
...
}));
// list-products.component.jsx
const dispatch = useDispatch(); // retorna store.dispatch
dispatch({ type: 'ADD_PRODUCT', payload: { id: 123, name: 'product 1', ... } });
...