Skip to content

Instantly share code, notes, and snippets.

@seanmodd
Last active February 2, 2022 19:54
Show Gist options
  • Save seanmodd/7d25dcc1710255c62bb95e5c11baa7fa to your computer and use it in GitHub Desktop.
Save seanmodd/7d25dcc1710255c62bb95e5c11baa7fa to your computer and use it in GitHub Desktop.

Redux Actions

rdac - Redux: Action Creator (Preferred approach)

export const actionCreator = (payload) => {
  return {
    type: 'ACTION_TYPE',
    payload
  }
};

action - Redux: Dispatch Action (Preferred Async Await approach)

export const  = () => {
  return async dispatch => {
    try {

    } catch (e) {}
  };
};

rdat - Redux: Const of Action Type

export const ACTION_NAME = 'ACTION_NAME';

Redux Store

store - Redux: Store

import { reducerName } from './reducer'
import { createStore } from 'redux'

const store = createStore(reducerName)

export default store

provider - Redux: Provider from React-Redux

<Provider store={store}>
  Component
</Provider>

Redux Reducer

rdr - Redux: Reducer (Preferred Approach)

const initialState = {}

const reducerName = (state = initialState, action) => {
  const newState = { ...state };

  if (action.type === 'ACTION_TYPE'){
    // return something 
  } else {
    return newState
  };
};

export default reducerName;

rxreducer - Redux: Reducer

const initialState = {};

export default (state = initialState, { type, payload }) => {
  switch (type) {
    case first:
      return { ...state, ...payload };

    default:
      return state;
  }
};

rdcr - Redux: Combine Reducer

import { combineReducers } from 'redux';

import reducerName from 'reducerPath';

export default combineReducers({
  
});

Redux Selectors

selector - Redux: Select

export const selectorName = createSelector(
  [filter1, filter2]
  (filter1, filter2) => {

  }
)

rxselect - Redux: Select

import { createSelector } from 'reselect';

export const first = (state) => state.second;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment