React onClick and preventDefault() link refresh/redirect?

前端 未结 13 795
生来不讨喜
生来不讨喜 2020-11-30 06:04

I\'m rendering a link with react:

render: ->
  `upvote`

Then, above I hav

13条回答
  •  难免孤独
    2020-11-30 06:49

    This is because those handlers do not preserve scope. From react documentation: react documentation

    Check the "no autobinding" section. You should write the handler like: onClick = () => {}

提交回复
热议问题