How to put multiple JSX expressions on onload in React

Asked

Viewed 88 times

1

Is there any way to put two JSX expressions on onload? Every time I try to put two expressions he doesn’t recognize the second expression. I wanted to try to put it this way :

<td onLoad={e < index.length ? e = e : e++}{i >= proximo_mes.length ? i = i : null}></td>
  • if you can put the full example of your claim only this passage does not say much, I particularly would not use onLoad because I think there are better ways to solve, but without the code in full and without a context it becomes complicated. The answer in creating a arrow function is not exactly why you have to create a function to solve this problem and then enter common or anonymous functions

1 answer

3


Just use an Arrow Function, in which case it would be:

<td
  onLoad={() => {
    e < index.length ? (e = e) : e++;
    i >= proximo_mes.length ? (i = i) : null;
  }}
></td>;

But I recommend using this in a separate function and only point to the function, for example:

const load = () => {
  e < index.length ? (e = e) : e++;
  i >= proximo_mes.length ? (i = i) : null;
}

<td onLoad={load}></td>
  • thanks , I implemented in my code but now is giving error : Expected an assignment or Function call and Instead saw an Expression no-unused-Expressions

Browser other questions tagged

You are not signed in. Login or sign up in order to post.