File tree Expand file tree Collapse file tree 10 files changed +2309
-2148
lines changed Expand file tree Collapse file tree 10 files changed +2309
-2148
lines changed Original file line number Diff line number Diff line change 1515 "devDependencies" : {
1616 "babel-core" : " ^6.26.3" ,
1717 "babel-jest" : " ^23.4.2" ,
18- "babel-loader" : " ^7.1.5 " ,
18+ "babel-loader" : " ^8.0.6 " ,
1919 "babel-polyfill" : " ^6.26.0" ,
2020 "babel-preset-env" : " ^1.7.0" ,
2121 "babel-preset-react" : " ^6.24.1" ,
3636 "webpack-dev-server" : " ^3.1.5"
3737 },
3838 "dependencies" : {
39+ "@babel/core" : " ^7.4.5" ,
40+ "@babel/preset-env" : " ^7.4.5" ,
41+ "@babel/preset-react" : " ^7.0.0" ,
3942 "react" : " ^16.4.2" ,
40- "react-dom" : " ^16.4.2"
43+ "react-dom" : " ^16.4.2" ,
44+ "react-redux" : " ^7.1.0" ,
45+ "redux" : " ^4.0.1" ,
46+ "redux-thunk" : " ^2.3.0"
4147 },
4248 "babel" : {
4349 "presets" : [
Original file line number Diff line number Diff line change 1+ {
2+ "presets" : [" @babel/preset-env" , " @babel/preset-react" ]
3+ }
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ const Header = () => (
66 < h1 className = "animate-top" > React and Webpack :)</ h1 >
77 < hr className = "gray-border" />
88 < p > Hello world!</ p >
9+ < p > Hurray!!! We now have Redux setup added to our configuration 🎉🎉🎉</ p >
910 </ div >
1011 </ div >
1112) ;
Original file line number Diff line number Diff line change 1+ import { connect } from 'react-redux' ;
2+ import { sampleAction } from '../store/actions/sample.actions' ;
3+ // import your actual component here
4+ const SampleComponent = ( ) => { } ;
5+
6+ const mapStateToProps = ( state , ownProps ) => {
7+ return { } ;
8+ } ;
9+
10+ const mapDispatchToProps = dispatch => {
11+ return {
12+ testSampleAction : dispatch ( sampleAction ( ) )
13+ } ;
14+ } ;
15+
16+ export default connect ( mapStateToProps , mapDispatchToProps ) ( SampleComponent ) ;
Original file line number Diff line number Diff line change 1+ // export all action types relating to this file in any case it's needed in other files
2+ export const SAMPLE_ACTION = 'SAMPLE_ACTION' ;
3+ export const SAMPLE_ACTION_WITH_PAYLOAD = 'SAMPLE_ACTION_WITH_PAYLOAD' ;
4+
5+ export const sampleAction = ( ) => dispatch => {
6+ dispatch ( {
7+ type : SAMPLE_ACTION ,
8+ } ) ;
9+ } ;
10+
11+ export const sampleActionWithPayload = ( ) => dispatch => {
12+ const payload = { } ;
13+
14+ dispatch ( {
15+ type : SAMPLE_ACTION_WITH_PAYLOAD ,
16+ payload,
17+ } ) ;
18+ } ;
Original file line number Diff line number Diff line change 1+ import { createStore , applyMiddleware , compose } from 'redux' ;
2+ import thunk from 'redux-thunk' ;
3+ import rootReducer from './reducer' ;
4+
5+ const composeEnhancers = window . __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose ;
6+ export default ( ) => createStore (
7+ rootReducer ,
8+ composeEnhancers ( applyMiddleware ( thunk ) ) ,
9+ ) ;
Original file line number Diff line number Diff line change 1+ import { combineReducers } from 'redux' ;
2+ import sampleReducer from './reducers/sample.reducers' ;
3+
4+ export default combineReducers ( {
5+ sampleReducer,
6+ } ) ;
Original file line number Diff line number Diff line change 1+ import * as Actions from '../actions/sample.actions' ;
2+
3+ const initialState = {
4+ hasInitialState : true ,
5+ } ;
6+
7+ const sample = ( state = initialState , action ) => {
8+ switch ( action . type ) {
9+ case Actions . SAMPLE_ACTION :
10+ return { nothing : null } ;
11+ case Actions . SAMPLE_ACTION_WITH_PAYLOAD :
12+ return {
13+ ...state ,
14+ dataFromWherever : action . payload ,
15+ } ;
16+ default :
17+ return state ;
18+ }
19+ } ;
20+
21+ export default sample ;
Original file line number Diff line number Diff line change 11import 'babel-polyfill' ;
22import React from 'react' ;
33import ReactDOM from 'react-dom' ;
4+ import { Provider } from 'react-redux' ;
5+
6+ import configureStore from './app/store/configure-store' ;
47import App from './app/App' ;
58import './index.scss' ;
69
7- export const Root = ( ) => < App /> ;
10+ export const Root = ( ) => < Provider store = { configureStore ( ) } > < App /> </ Provider > ;
811
912ReactDOM . render ( < Root /> , document . getElementById ( 'root' ) ) ;
You can’t perform that action at this time.
0 commit comments