Is there a right way to pass data into a React component from the HTML page?

前端 未结 4 398
悲&欢浪女
悲&欢浪女 2021-01-31 08:29

I have a React app like this.

var X = React.createClass({
  componentDidMount: function() {
    fetch(this.props.feed).then(...);
  }
  render: function() {
             


        
4条回答
  •  走了就别回头了
    2021-01-31 09:00

    I have used data- attributes for various props, then passed all the props using destructuring {...dataset}, for example:

    HTML:

    JS:

    var root = document.getElementById('app');
    ReactDOM.render(, root);
    

    Edit: demo fiddle
    Edit 2018: updated fiddle

提交回复
热议问题