Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

113
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda