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

前端 未结 4 444
悲&欢浪女
悲&欢浪女 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:04

    React Habitat is a framework that facilitates this if you want something reusable and extendable.

    You register React components like this

    containerBuilder.register(Feed).as('Feed')
    

    Then define targets in the HTML like this with props

    React Habitat will wire these up any time it appears in the HTML.

    Disclosure: I am one of the head maintainers of this framework.

提交回复
热议问题