onClick handler not registering with ReactDOMServer.renderToString

前端 未结 2 859
南笙
南笙 2021-02-07 21:50

I am trying to copy this fiddle: http://jsfiddle.net/jhudson8/135oo6f8/

(I also tried this example http://codepen.io/adamaoc/pen/wBGGQv and the same onClick

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-07 22:26

    React DOM render to string only sends the initial HTML as a string without any JS.
    You need a client side react router as well which will attach the required JS handlers to the HTML based on their react-id's. The JS needs to run on both sides.
    Universal rendering boilerplate for quick start. https://github.com/erikras/react-redux-universal-hot-example
    Another question which is similar to yours. React.js Serverside rendering and Event Handlers

提交回复
热议问题