简体   繁体   English

React类未渲染

[英]React Class is Not Rendering

The react class myComponent is not rendering inside the element example1 . react类myComponent不在元素example1内部呈现。

what I am able to get in console is 我能够在控制台中获得的是

You are using the in-browser JSX transformer. 您正在使用浏览器中的JSX转换器。 Be sure to precompile your JSX for production - http://facebook.github.io/react/docs/tooling-integration.html#jsx 一定要预编译JSX用于生产- http://facebook.github.io/react/docs/tooling-integration.html#jsx

code

    <script type="text/jsx">
            var myComponent = React.createClass({
              render: function() {
                return (
                    <h2>{this.props.name} wants to eat {this.props.food}</h2>
                );
              }
            });

React.render(
        <div>
            <myComponent food="fruits" name="Raj1"/>
            <myComponent food="Veggies" name="Raj2"/>
            <myComponent food="Chicken" name="Raj3"/>
            <myComponent food="Burger" name="Raj4"/>
        </div>, 
            document.getElementById('example1'));
    </script>

You must capitalize your react classes 您必须大写您的反应班

var MyComponent = React.createClass({
    render: function() {
          return (
             <h2>{this.props.name} wants to eat {this.props.food}</h2>
        );
     }
 });

working fiddle example 工作小提琴的例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM