I am new to the reaction, so please excuse me if I cannot correctly formulate this question. So I have this jsx script file that maps my reaction components to my view as soon as it loads. Initially, in this script file, I have no data to display in my component, so I am not processing any of my subcomponents. However, at some later moment, when I get data from, say, a web service, I would really like to display components with this data again.
The components in my JSX script file have no state, it just needs to show the data that I pass into it.
The JSX script loads a fine and displays components with initially no data specified in the JSX file itself. However, when I try to make this component again in another Javascript file, it gives me a reference error, the component is undefined.
Is there a JSX nation, / *** @jsx React.DOM * / to create a completely different namespace? If so, how can I access it? And what's the best way to remake components with new data from your JSX script file. Thanks in advance!:)
/ ** Edited * / guys, sorry for not adding the code .. instead let me ask a simple question .. how can I access the react component in my jsx script from my javascript file?
/ ** Edited * / Ok guys, here is a sample code:
var Avatar = React.createClass({ render: function() { return ( <div> <ProfilePic username={this.props.username} /> <ProfileLink username={this.props.username} /> </div> ); } }); var ProfilePic = React.createClass({ render: function() { return ( <img src={'http://graph.facebook.com/' + this.props.username + '/picture'} /> ); } }); var ProfileLink = React.createClass({ render: function() { return ( <a href={'http://www.facebook.com/' + this.props.username}> {this.props.username} </a> ); } }); React.render( <Avatar username="pwh" />, document.getElementById('example') );
Thus, the above code can be embedded in your html tags specified as a jsx script, or downloaded externally. Pay attention to the username support in the Avatar element (the top of the most responsive component in the hierarchy), the problem is how can we reuse the Avatar component in another javasccript file with a different username? All is well and good, if you set it up and run. The first component loads, it sets pwh as the username. However, how can I access this element from my javascript (i.e., Outside the jsx script) and repeat it with the new username value? Is it possible?