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

135
Views
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 answers
Answer question

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 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!