From a365fa7d58476f7733a2d0b0a77411f3eae0ba39 Mon Sep 17 00:00:00 2001 From: Camerin Date: Wed, 15 Sep 2021 15:48:57 -0400 Subject: [PATCH] Redux is now hooked up and functional. --- src/actions/index.js | 11 +++++++++++ src/apis/github.js | 5 +++++ src/index.js | 18 ++++++++++++------ src/reducers/githubReducer.js | 11 +++++++++++ src/reducers/index.js | 7 +++++++ 5 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 src/actions/index.js create mode 100644 src/apis/github.js create mode 100644 src/reducers/githubReducer.js create mode 100644 src/reducers/index.js diff --git a/src/actions/index.js b/src/actions/index.js new file mode 100644 index 0000000..306218d --- /dev/null +++ b/src/actions/index.js @@ -0,0 +1,11 @@ +import github from '../apis/github'; + +export const getRepos = () => async (dispatch, getState) => { + const response = await github.get('/users/RaspberryProgramming/repos'); + //console.log(response); + + dispatch({ + type: 'GET_REPOS', + payload: response.data, + }); +}; \ No newline at end of file diff --git a/src/apis/github.js b/src/apis/github.js new file mode 100644 index 0000000..0004350 --- /dev/null +++ b/src/apis/github.js @@ -0,0 +1,5 @@ +import axios from 'axios'; + +export default axios.create({ + baseURL: 'https://api.github.com' +}); \ No newline at end of file diff --git a/src/index.js b/src/index.js index 1e9e8ff..05d9540 100644 --- a/src/index.js +++ b/src/index.js @@ -1,12 +1,18 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import './index.css'; -import App from './components/App'; +import { Provider } from 'react-redux'; +import { createStore, applyMiddleware, compose } from 'redux'; +import reduxThunk from 'redux-thunk'; +import App from './components/App'; +import reducers from './reducers'; + +const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; +const store = createStore(reducers, composeEnhancers(applyMiddleware(reduxThunk))); ReactDOM.render( -
- -
, - document.getElementById('root') + + + , + document.querySelector('#root') ); diff --git a/src/reducers/githubReducer.js b/src/reducers/githubReducer.js new file mode 100644 index 0000000..f5df2d0 --- /dev/null +++ b/src/reducers/githubReducer.js @@ -0,0 +1,11 @@ +let githubReducer = (state={}, action) => { + switch(action.type) { + case 'GET_REPOS': + return { ...state, repos: action.payload }; + default: + return state; + } + }; + + +export default githubReducer; \ No newline at end of file diff --git a/src/reducers/index.js b/src/reducers/index.js new file mode 100644 index 0000000..4b69bbb --- /dev/null +++ b/src/reducers/index.js @@ -0,0 +1,7 @@ +import { combineReducers } from "redux"; + +import githubReducer from './githubReducer' + +export default combineReducers({ + github: githubReducer, +});