Skip to content

Instantly share code, notes, and snippets.

View wesleymonaro's full-sized avatar

Wesley Monaro wesleymonaro

  • Mogi das Cruzes, SP, Brazil
View GitHub Profile
const app = require('express')();
app.get('/users', (req, res) => res.send('Hello Users API'));
app.listen(3001, () => console.log(`Users API listening on port 3001!`));
const app = require('express')();
app.get('/products', (req, res) => res.send('Hello Products API'));
app.listen(3002, () => console.log(`Products API listening on port 3002!`));
module.exports = {
USERS_API_URL: 'http://localhost:3001',
PRODUCTS_API_URL: 'http://localhost:3002',
};
const express = require('express');
const httpProxy = require('express-http-proxy');
const app = express();
const port = 3000;
const {
USERS_API_URL,
PRODUCTS_API_URL,
} = require('./URLs');
const userServiceProxy = httpProxy(USERS_API_URL);
import React, { Component } from "react";
class App extends Component {
render() {
return (
<div className="App">
<header className="App-header">Teste Redux</header>
</div>
);
}
}
import ReduxThunk from "redux-thunk";
import reducers from "./appReducers";
import { applyMiddleware, createStore } from "redux";
const middleware = [ReduxThunk];
const store = createStore(reducers, applyMiddleware(...middleware));
export default store;
export const compraMateriais = () => {
return dispatch => {
// Código para fazer requisição a uma API
dispatch({
type: "COMPRA_MATERIAL",
payload: {
nome: "Caixa de canetas",
qtd: 20
}
const INITIAL_STATE = {
materiais: []
};
export default (state = INITIAL_STATE, action) => {
switch (action.type) {
case "COMPRA_MATERIAL":
return { ...state, materiais: [...state.materiais, action.payload] };
default:
import { combineReducers } from "redux";
import reducer from "./reducer";
const reducers = combineReducers({
reducer,
// caso tenha mais reducers, inclua aqui
});
export default reducers;
import React, { Component } from "react";
import { Provider } from "react-redux";
import store from "./store";
class App extends Component {
render() {
return (
<Provider store={store}>
<div className="App">
<header className="App-header">Teste Redux</header>