Skip to content

Instantly share code, notes, and snippets.

@seanmodd
Last active January 31, 2022 08:26
Show Gist options
  • Save seanmodd/ccdde6c6389c8b4f4f77971aa1266670 to your computer and use it in GitHub Desktop.
Save seanmodd/ccdde6c6389c8b4f4f77971aa1266670 to your computer and use it in GitHub Desktop.
Amazing Redux Snippets! Must study...

Snippets To Remember

action - Redux actionCreator

export const  = () => {
  return async dispatch => {
    try {
    
    } catch (e) {}
  };
};

rac - Redux actionCreator

export const actionCreator = (payload) => ({
  type: actionType,
  payload
})

store - Redux Store

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

const store = createStore(reducerName)

export default store

provider - React-Redux Provider

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

rsc - React Stateless Component

import React from 'react';

const BugsList = () => {
  return (
    <div>
      
    </div>
  );
};

export default BugsList;

rsf - React Stateless Function

import React from 'react';

function BugsList(props) {
  return (
    <div>
      
    </div>
  );
}

export default BugsList;

rxaction - Redux Action

export const first = (payload) => ({
  type: second,
  payload,
});

rxconst - Redux Constant

export const first = 'first';

rxreducer - Redux Reducer

const initialState = {};

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

    default:
      return state;
  }
};

selector - Redux Select

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

rxselect - Redux Select

import { createSelector } from 'reselect';

export const first = (state) => state.second;

rxslice - Redux Slice

import { createSlice } from '@reduxjs/toolkit';

const initialState = {};

const BugsList = createSlice({
  name: second,
  initialState,
  reducers: {},
});

export const {} = BugsList.actions;

export default BugsList.reducer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment