0

I would like to calculate the pf of salary using the basic salary like this:

state = {
        fgsSalary: 0,
        basicSalary: 0,
        //pf: this.state.basicSalary * 0.12
        //pf: this.basicSalary * 0.12
        //pf: basicSalary * 0.12
}

I tried all three ways but nothing works. If there's any way please tell.

Rahul
  • 25
  • 8

1 Answers1

1

You could use getter, benefits you to access property as a property:

var state = {
  fgsSalary: 1,
  basicSalary: 2,
  get pf() {
    return this.basicSalary * 0.12
  }
};
console.log(state.pf);
shrys
  • 5,860
  • 2
  • 21
  • 36