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

112
Views
Can we use a function inside a selector in react js

I have recently got stucked at a place where I want to call a function that is accessing the store values inside a selector.

So the scenario is something like this, inside a selector I'm having some initial values but during a particular functionality I want to update the selector response with some extra attributes which I'm getting from a function. So that, at the end I got the initial values with some modifications, is it possible and how should we approach the problem?

Will be providing code snippet of the selector, function

In the selectOngoingFee selector I want to call constructData function and for a special condition I need the selector to manipulate the returnObj. I couldn't show you the exact implementation, actually I was stuck at the very first step so if I get to know how I can I call constructData and pass store in that will be very helpful.

selectAccountFeeRate is another selector which gives the result as {
  aofValue: {
    pensionFee: {
      amount: '7',
      type: 'AOF',
      taxIncluded: 'NO'
    }
  }
}

const constructData = (store, accountNumber) => {
  const pensionSavingAOF = selectAccountFeeRate(state, accountNumber) || {}
  const pensionSavingData = {
    fees: [{
      feeType: 'AOF',
      value: pensionSavingAOF.aofValue.pensionFee.amount,
      isVatIncluded: pensionSavingAOF.aofValue.pensionFee.taxIncluded === YES

    }]
  }
  return {
    pensionSaving: pensionSavingData
  }
}

const selectOngoingFee = createSelector([selectRetrievedQuoteDetails], (quoteDetails)) => {
  const {
    ongoingFee
  } = quoteDetails || {}
  const pensionSaving = {
    fees: []
  }
  if (!isEmpty(ongoingFee)) {
    ongoingFee.forEach((item) => {
      const data = {
        feeType: 'AOF',
        value: item.amount,
        isVatIncluded: item.taxIncluded
      }
      if (item.accountType === 'PENSION_SAVING_ACCOUNT') {
        pensionSaving.fees.push(data)
      }
    })
  }
  const returnObj = {
    ...(pensionSaving.fees.length ? {
      pensionSaving
    } : {})
  }
  return returnObj
}

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Although I have asked this question but after reading a lot of data. I came to know that the only way is to create another function, pass the constructData and select OngoingFee as arguments and manipulate it. Hope my understanding is correct here.

about 4 years ago · Santiago Trujillo Report
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!