we going to build star wars and wrather app with react/redux
================================================================
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;
import { combineReducers } from "redux";
export default combineReducers({});
const initalState = {
data: []
};
export const dataReducer = (state = initalState, action) => {
switch (action.type) {
case "GET_DATA":
return {
...state,
data: action.payload
};
default:
return state;
}
};
import axios from "axios";
export const getData = () => dispatch => {
axios.get("https://swapi.co/api/people").then(res =>
dispatch({
type: "GET_DATA",
payload: res.data
})
);
};