Redux is now hooked up and functional.

This commit is contained in:
Camerin 2021-09-15 15:48:57 -04:00
parent 4b164b6ed9
commit a365fa7d58
5 changed files with 46 additions and 6 deletions

11
src/actions/index.js Normal file
View File

@ -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,
});
};

5
src/apis/github.js Normal file
View File

@ -0,0 +1,5 @@
import axios from 'axios';
export default axios.create({
baseURL: 'https://api.github.com'
});

View File

@ -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(
<div>
<Provider store={store}>
<App/>
</div>,
document.getElementById('root')
</Provider>,
document.querySelector('#root')
);

View File

@ -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;

7
src/reducers/index.js Normal file
View File

@ -0,0 +1,7 @@
import { combineReducers } from "redux";
import githubReducer from './githubReducer'
export default combineReducers({
github: githubReducer,
});