Home > Software engineering >  call same function inside function react
call same function inside function react

Time:02-26

Hey I'm trying to see a way I can call a function inside the same function but I'm getting an ESLint error when I do 'function' this was used before it was defined. no-use-before-define. There is a purpose I'm doing this when I call function a based on response I need to trigger 'b' if response is not satisfied then I need to call 'a' again

const a = () => {
  b();
}

const b = () => {
  a();
}

CodePudding user response:

Disable the lint for that line, then, with e.g.

const a = () => {
  // eslint-disable-next-line no-use-before-define
  b();
}

It's just a stylistic warning.

CodePudding user response:

To have dependent functions despite no-use-before-define, you could use callback functions.

Assuming you call function a first - pass function b as an argument to function a, then invoke that argument there to call function b.

const a = (functionB) => {
  functionB();
}

const b = () => {
  a();
}

a(b);
  • Related