Skip to content

Latest commit

 

History

History
75 lines (54 loc) · 1.27 KB

README.md

File metadata and controls

75 lines (54 loc) · 1.27 KB

redux workshop for supervisa

we going to build star wars and wrather app with react/redux

================================================================

Store.js



import { createStore, applyMiddleware, compose } from "redux";
import thunk from "redux-thunk";
import rootReducer from "./reducer/indexReducer";

const initialState = {};
const middleware = [thunk];

const store = createStore(
  rootReducer,
  initialState,
  compose(
    applyMiddleware(...middleware),
    window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
  )
);

export default store;



indexReducer.js


import { combineReducers } from "redux";

export default combineReducers({});

dataReducer.js


const initalState = {
  data: []
};

export const dataReducer = (state = initalState, action) => {
  switch (action.type) {
    case "GET_DATA":
      return {
        ...state,
        data: action.payload
      };
    default:
      return state;
  }
};

getData.js


import axios from "axios";

export const getData = () => dispatch => {
  axios.get("https://swapi.co/api/people").then(res =>
    dispatch({
      type: "GET_DATA",
      payload: res.data
    })
  );
};