redux action

import { createActions, handleActions, combineActions } from 'redux-actions';

const defaultState = { counter: 10 };

const { increment, decrement } = createActions({
  INCREMENT: (amount = 1) => ({ amount }),
  DECREMENT: (amount = 1) => ({ amount: -amount })
});

const reducer = handleActions({  
  [combineActions(increment, decrement)]: (state, action) => {
      return { ...state, counter: state.counter + action.payload.amount };
    }
  },
  defaultState
);

export default reducer;

3.67
3
Awgiedawgie 440220 points

                                    //npm i redux-actions or yarn add redux-actions

// single action creator
export const incAsyncCreator = createAction("INC");
export const decAsyncCreator = createAction("DEC");

// single action creator using - single reducer 
export const incReducer = handleAction(
  incAsyncCreator,
  (state, action) => ({
    ...state,
    counter: state.counter + 1,
    success: action.payload.success
  }),
  counterState
);

// single action creator using - single reducer 
export const decReducer = handleAction(
  incAsyncCreator,
  (state, action) => ({
    ...state,
    counter: state.counter + 1,
    success: action.payload.success
  }),
  counterState
);


//multiple action creator
export const { increment, decrement } = createActions({
  increment: (payload) => ({ ...payload }),
  decrement: (payload) => ({ ...payload })
});

// multiple action creator using - multiple reducer 
export const counterReducer = handleActions(
  {
    [increment]: (state, action) => ({
      ...state,
      counter: state.counter + 1,
      success: action.payload.success
    }),
    [decrement]: (state, action) => ({
      ...state,
      counter: state.counter - 1,
      success: action.payload.success
    })
  },
  counterState
);

3.67 (3 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
dispatch an action to redux whats redux action how to create action redux how to create actionin redux react redux action hook writing action in redux in react js action and redux redux action instructions action react-redux where to put actions in redux what is actions in redux What is a Redux Action? what is a redux action dispatch action on redux how to create action in react redux how to call a action in redux what are action in redux creation action redux any action redux how to use redux action in a class component 2. What is action? in redux what is Redux actions making action with redux using redux actions how to make action in redux what is action in react redux call action method in redux redux how to dispatch an action create action in react redux react redux actions example use redux action redux actions react redux how to define action redux handle an action how to create an action in redux can i dispatch action redux redux dispatch in action redux action sample actions redux react how to create action in redux call action in action redux redux actions exampl how to create actions in redux action name in redux redux action (dispatch) what does an action contain? redux redux what are actions Redux dispatch action from action redux actions definition define an action redux what are action redux redux call action from action what is a actionsin redux redux action for create new action function in redux action object in redux redux action object define a redux action calling action from action redux how to use an action react reduxx redux action redux set action with react-redux redux action react what is redux action actions in react redux dispatch an action redux why do we use action in redux can redux action return how to dispatch an action in redux action dispatch redux create action redux why create an action redux redux action state what is an action in redux call action inside actions redux redux action ex redux dispatch action in action what is the better way to make action redux react createaction redux actions how to dispatch action in redux redux state in action react redux action model react redux action, what is an action redux React / Redux action redux dispatch action action examples in redux redux full action redux action function how to write action in redux react redux action props action in redux example what are actions redux react redux action example create redux action redux dispatch tutorial redux create action what are redux actions action in redux object dispatch in action redux action example redux what is the action in redux redux calling action from action how to write redux action create action react-redux create action redux action creaters redux What is a Redux action ? react redux use action how to use redux actions Action object redux action react redux react redux actions create what happens after we dispatch an action in redux redux in action what action does in redux call an action in action redux action in action redux redux creat an action redux use actions how to write actions in redux dispatch redux action action works redux state action started redux redux actions example how to create action in redux react what are actions in redux Redux actions in a React application how to set up an action in react redux class component in redux action actions in redux creating action in redux hoks react redux actions redux-action example what is action in redux action redux js redux usedispatch action redux presist redux extension action in redux action redux redux init action redux action from js dispatch action redux actions dispatch redux how to create seperated actions file for redux create action in redux dispatch react action in ract js how to get action working in redux actions. js action with payload redux action types file putting strings in redux How do you dispatch actions dispatch redux with action action in react redux action dispatch send action as dispatch fot actions for redux dispatch react redux dispatch actions how to define action in redux payload in react redux get payload from dispatch react payload recordSnap action.payload PayloadAction redux dispatch in action react how to apply action on redux type and payload in redux actions in redux redux-actions npm action creator and reducer payload in redux action how to use action in react redux redux action creator example using redux actions with react sending redux actions to controllers react redux action syntax for redux action What function use to trigger an action in Redux ? react-redux get actions action creators in redux where we can define action in redux redux action example actions redux redux actin what is previous action , action and next action in redux redux create and dispatch action redux react actions react js actions adalah react dispatch redux add action redux payload what is react action how to define a action in redux how to import actions in rdux redux action creators add an object using action redux react action creator redux why my redux action are numerouos redux action types dispatch redux react action dispatch dispatching actions redux how to dispatch an action redux dispatch an action redux payload object payload react action react redux dispatch redux actions npm redux acions redux actions redux action
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source