Last active
March 19, 2020 16:37
-
-
Save AstralJohn/c4b6e0dc75634cd96e29d0c32a634f3d to your computer and use it in GitHub Desktop.
React Redux Setup With DevTools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react"; | |
| import { connect } from "react-redux"; | |
| // Import your actions from your action's index.js file | |
| // import { action1, action2 } from '../actions' | |
| const ExampleComponent = ({ stateKey1, stateKey2, action1, action2 }) => { | |
| // alternatively, ExampleComponent = (props) => .... | |
| // const {stateKey1, stateKey2, action1, action2} = props; | |
| return <div>Example</div>; | |
| }; | |
| const mapStateToProps = ({ stateKey1, stateKey2 }) => ({ | |
| stateKey1, | |
| stateKey2 | |
| }); | |
| export default connect(mapStateToProps, { | |
| // action1, | |
| // action2 | |
| })(ExampleComponent); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react"; | |
| import ReactDOM from "react-dom"; | |
| import "./index.css"; | |
| import App from "./components/App"; | |
| import { Provider } from "react-redux"; | |
| import store from "./store"; | |
| ReactDOM.render( | |
| <Provider store={store}> | |
| <App /> | |
| </Provider>, | |
| document.getElementById("root") | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { combineReducers } from "redux"; | |
| /* | |
| * Create reducers inside your reducers directory | |
| * Example: import alerts from "./alerts"; | |
| */ | |
| export default combineReducers({ | |
| // alerts, | |
| deleteMe: () => "Delete Me" | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import rootReducer from "./reducers"; | |
| import thunk from "redux-thunk"; | |
| import { createStore, applyMiddleware } from "redux"; | |
| import { composeWithDevTools } from "redux-devtools-extension"; | |
| const middleware = [thunk]; | |
| export default createStore( | |
| rootReducer, | |
| composeWithDevTools(applyMiddleware(...middleware)) | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment