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

136
Visualizações
Calling same function from two another functions works only for first in React Native

I have problem to call one function in another two functions. Two functions, where I will call function is same. I am using mapping. All three functions I added in constructor, but I have no idea why this happend.

Here is my code:

class medicalDataForAll extends React.Component{ 
    constructor(props) {
        super(props)
        this.getLastWeekHeartRate = this.getLastWeekHeartRate.bind(this)
        this.getLastWeekHeartRateX = this.getLastWeekHeartRateX.bind(this)
        this.getLastWeekHeartRateY = this.getLastWeekHeartRateY.bind(this)
        }

    getLastWeekHeartRate() {
        var daysValues = [];
       
        this.getLastWeekHeartRateDatesXY().forEach((a) => {
            
            if (!this[a[0].day]) {
                this[a[0].day] = { day: a[0].day, value: 0};
                daysValues.push(this[a[0].day]);
            }

            this[a[0].day].value += a[0].value;
            this[a[0].day].month = a[0].month;
 
        }, Object.create(null));


        var days = this.getLastWeekHeartRateDatesXY().map((a) => a[0].day)
        var daysCounts = [...new Set(days)].map(e =>({
                        day: e,
                        count: days.filter(n => n===e).length }))
        
        var newArray = daysValues.map(function(value, index) {
            return {
                xAxe:  "" + daysValues[index].day + '/' + daysValues[index].month + "",
                yAxe: parseInt(daysValues[index].value / daysCounts[index].count)    
            }
          });
        
        //console.log(newArray.reverse())
        return newArray.reverse()
    }

    getLastWeekHeartRateX() {
        const value = this.getLastWeekHeartRate().map((a) => a.xAxe)
       
        console.log(value)
        return value
    }

    getLastWeekHeartRateY() {
        const value = this.getLastWeekHeartRate().map((a) => a.xAxe)
        
        console.log(value)
        return value
    }

Problem is showing getLastWeekHeartRateY(), the output of function is empty. Thank you!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

After searching problem I can load all functions in render().

Problem was timing. I had many functions and it was not enough to execute function in render(). I just created in state chartData [] and after this updated state und used in both functions.

Code below:


class medicalDataForAll extends React.Component{ 
    constructor(props) {
        super(props)
            this.state = {
               chartData = {}
            }
        }

    componentDidMount(){
        this.setState({
            chartData: this.getLastWeekHeartRate()
        })
    }

    getLastWeekHeartRate() {...}

    getLastWeekHeartRateX() {
        let value = this.state.chartData.map((a) => a.xAxe)
       
        return value
    }

    getLastWeekHeartRateY() {
        let value = this.state.chartData.map((a) => a.xAxe)

        return value
    }

Have a nice coding!

about 4 years ago · Juan Pablo Isaza 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