简体   繁体   中英

Creating react element with custom attributes

I am new to react, first app. I am trying to create a custom element with attributes of data. For the time being I am writing in plain ES5 so no JSX, Babel or ES6 yet. That will be next.

var myEl = React.createClass({
    displayName : 'elCont',
    render: function() {
        return(
            React.createElement('My-Shiney-Element', {
                data: data,
                conf: conf
            })
         );
     )}


var data = [1,2,3,4,5,6];
var conf = {"show": true};

I can see in the html <my-shiney-element><\\my-shiney-element> But not the attributes?

You can use

<my-shiney-element foo="bla"><\my-shiney-element> 

in you code you can access "foo" with "this.props.foo"

https://facebook.github.io/react/docs/transferring-props.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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