Pass props from template into react.js root node

前端 未结 3 2046
日久生厌
日久生厌 2021-01-04 11:03

I may have missed something, but here goes. If I have:

var Swoosh = React.createClass({
  render: function() {
    ret         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-04 11:47

    There is a alternative way to achieve this by using data attributes in html. Here's a small example: In html, you add as much properties with the data prefix as you want:

    All data properties will be automatically converted to CamelCased properties in the element's dataset property. Pass this property to your React component and you're done:

    let element = document.getElementById('root')
    ReactDOM.render(, element)
    

提交回复
热议问题