How to conditionally add or not onClick on a div in react?

前端 未结 6 1416
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-01 02:26

I would like to know if it is possible to set onClick on a div element in react based on the value of a property in my case canClick.

I am awar

6条回答
  •  感情败类
    2021-02-01 02:58

    If you opt for a different falsy value instead of undefined in this ternary (i.e. false or null) React (currently) throws the following warning:

    "If you used to conditionally omit it with onClick={condition && value}, pass onClick={condition ? value : undefined} instead."

    Edit 2020-01-05: only false throws the above error (React source code here).

提交回复
热议问题