Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
how to use one reducer value in another reducer of same slice in redux toolkit?

**strong text** I want to use buy reducer state value in exchange reducer. How can I access that?

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

export const cryptoSlice = createSlice({
  name: "crypto",
  initialState: {
    coins: [],
    total: 0,
  },
  reducers: {
    buy: (state, action) => {
      state.total += +action.payload.input;
      state.coins.length > 0
        ? state.coins.map((coin) => {
            if (coin.cryptoCoin.id === action.payload.cryptoCoin.id) {
              coin.input = +action.payload.input + +coin.input;
            } else {
              state.coins.push(action.payload);
            }
          })
        : state.coins.push(action.payload);
    },
    exchange: (state, action) => {
      state.coins.push({
        cryptoCoin: action.payload.exchangeItem,
        input: action.payload.input,
      });
      console.log(state.coins);
    },
  },
});

export const { buy, exchange } = cryptoSlice.actions;

export default cryptoSlice.reducer;

So, this is my reducer. I want to use buy state value in my exchange reducer

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!