This extension contains code snippets for Redux when used with Reactjs (used by Andrew Smith).
In order to install an extension you need to launch the Command Palette (Ctrl + Shift + P or Cmd + Shift + P) and type Extensions. There you have either the option to show the already installed snippets or install new ones.
- JavaScript (.js)
- TypeScript (.ts)
- JavaScript React (.jsx)
- TypeScript React (.tsx)
import {Provider} from 'react-redux';$0
import PropTypes from 'prop-types';
import React from 'react';
import {connect} from 'react-redux';
const mapStateToProps = state => ({});
const mapDispatchToProps = dispatch => ({});
const mergeProps = (stateProps, dispatchProps, props) => ({});
const ${1:componentName} = ({}) => (
${0:<div></div>}
);
${1:componentName}.propTypes = {};
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(${1:componentName});
import {createActions} from 'redux-actions';
export default createActions({
${1:moduleName}: {
$0
}
});
'${1:moduleName}/${2:ACTION_NAME}',
${1:ACTION_NAME}: (${2:value}) => ({$3}),$0
${1:ACTION_NAME}: [
(${2:value}) => ({$3}),
(${2:value}) => ({$4})
],$0
import {handleActions} from 'redux-actions';
import * as actions from './actions';
const defaultState = {};
export default handleActions({
$0
}, defaultState);
[actions.${1.actionName}]: (state, payload, meta) => ({
...state,
$2
}),$0
import {createSelector} from 'reselect';
const getRoot = state => state$1;$0
const get${1:selectorName} = createSelector(${2:getRoot}, (${3:root}) => ({$4});$0
import {call, put, select, takeEvery} from 'redux-saga/effects';
import * as actions from './actions';
import * as selectors from './selectors';
export default [
$0
];
() => ${1:takeEvery}(actions.${2:actionName}, ${3:funcName}),$0
function* ${1:funcName}() {
$2
}$0
yield put(${1:actionName}($2);$0
yield select(selectors.${1:selectorName});$0
import {all, fork} from 'redux-saga/effects';
const sagas = [];
export default function* root() {
yield all(sagas
.map(saga => fork(saga))
);
};
import {combineReducers} from 'redux';
export default combineReducers({
$0
};
import createSagaMiddleware from 'redux-saga';
import {createStore, applyMiddleware, compose} from 'redux';
import reducer from './reducer';
import sagas from './sagas';
export default (initialState={}, additionalMiddleware = [], composeFunc = compose) => {
const middleware = [createSagaMiddleware()].concat(additionalMiddleware);
const store = createStore(
reducer, initialState, composeFunc(applyMiddleware(...middleware)));
if (module.hot) {
module.hot.accept('./reducer', () => {
const nextRootReducer = require('./reducer').default;
store.replaceReducer(nextRootReducer);
})
}
return store;};