0

I have an Arrow function to show the validation of form fields as:

showValidation = (field) => () => {
    console.log(field);
    this.setFieldState(field, {showValidation: true});

  }

Now I want to call to function from another function that loops through all the form entries as:

showAllValidations() {
    let self = this;
    for (let field of ['a', 'b', 'c', 'd', 'e', 'f', 'g']) {
      console.log(field);
      self.showValidation(field);
    }
  }

The console.log(field) in showValidation doesn't print anything while the console.log(field) in showAllValidations() displays all the fields so I assume that it is not getting called. I am new to ReactJs & ES6 and stuck with this problem for a long time.

David Maust
  • 8,080
  • 3
  • 32
  • 36
Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400
  • 1
    Try invoking the function returned from arrow function like this self.showValidation(field)(); – Thanigainathan Mar 10 '16 at 05:48
  • 1
    What's with the `thunk` chained on the end? If you have reason for it to be there, then you'll call `showValidation` like this. `['a', 'b', 'c', 'd', 'e', 'f', 'g'].map(field => this.showValidation(field)())` – Mulan Mar 10 '16 at 05:57
  • 1
    @azium: In fact the OP didn't ask a question at all :-) But the duplicate explains everything he needs to solve his problem, doesn't it? – Bergi Mar 10 '16 at 06:16

0 Answers0