Last active
March 21, 2021 21:44
-
-
Save amsterdamharu/cf93d154958207b4f938ec58e45ffbde to your computer and use it in GitHub Desktop.
stack overflow react redux snippet
This file contains 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
<!-- begin snippet: js hide: false console: true babel: true --> | |
<!-- language: lang-js --> | |
import * as React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import * as Redux from 'redux'; | |
import * as ReactRedux from 'react-redux'; | |
import * as Reselect from 'reselect'; | |
import * as immer from 'immer'; | |
const { Provider, useDispatch, useSelector } = ReactRedux; | |
const { createStore, applyMiddleware, compose } = Redux; | |
const { createSelector } = Reselect; | |
const { produce } = immer; | |
const initialState = {}; | |
//action types | |
const ADD_CARD_SUCCESS = 'ADD_CARD_SUCCESS'; | |
//action creators | |
const addCardSuccess = (payementMethodId, card) => ({ | |
type: ADD_CARD_SUCCESS, | |
payload: { payementMethodId, card }, | |
}); | |
const reducer = (state, { type, payload }) => { | |
return state; | |
}; | |
//selectors | |
const selectPaymentMethods = (state) => | |
state.paymentMethods; | |
//creating store with redux dev tools | |
const composeEnhancers = | |
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; | |
const store = createStore( | |
reducer, | |
initialState, | |
composeEnhancers( | |
applyMiddleware( | |
() => (next) => (action) => next(action) | |
) | |
) | |
); | |
const App = () => { | |
return 'hi' | |
}; | |
ReactDOM.render( | |
<Provider store={store}> | |
<App /> | |
</Provider>, | |
document.getElementById('root') | |
); | |
<!-- language: lang-html --> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.8.4/umd/react.production.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.4/umd/react-dom.production.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/4.0.5/redux.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-redux/7.2.0/react-redux.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/reselect/4.0.0/reselect.min.js"></script> | |
<script src="https://unpkg.com/[email protected]/dist/immer.umd.production.min.js"></script> | |
<div id="root"></div> | |
<!-- end snippet --> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment