onClick handler not registering with ReactDOMServer.renderToString

前端 未结 2 715
南笙
南笙 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

    0 讨论(0)
  • 2021-02-07 22:40

    None of the hooks will register with ReactDOMServer.RenderToString. If you want to accomplish server side rendering + hooks on your react component, you could bundle it on the client (webpack, gulp, whatever), and then also use ReactDOMServer.RenderToString on the server.

    Here's a blog post that helped me accomplish this: https://www.terlici.com/2015/03/18/fast-react-loading-server-rendering.html

    0 讨论(0)
提交回复
热议问题