Redux is now hooked up and functional.
This commit is contained in:
parent
4b164b6ed9
commit
a365fa7d58
|
|
@ -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,
|
||||
});
|
||||
};
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import axios from 'axios';
|
||||
|
||||
export default axios.create({
|
||||
baseURL: 'https://api.github.com'
|
||||
});
|
||||
18
src/index.js
18
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(
|
||||
<div>
|
||||
<App />
|
||||
</div>,
|
||||
document.getElementById('root')
|
||||
<Provider store={store}>
|
||||
<App/>
|
||||
</Provider>,
|
||||
document.querySelector('#root')
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import { combineReducers } from "redux";
|
||||
|
||||
import githubReducer from './githubReducer'
|
||||
|
||||
export default combineReducers({
|
||||
github: githubReducer,
|
||||
});
|
||||
Loading…
Reference in New Issue