facebook / jsx

The JSX specification is a XML-like syntax extension to ECMAScript.
http://facebook.github.io/jsx/
1.96k stars 133 forks source link

Using `this` in the element name. #43

Closed trusktr closed 8 years ago

trusktr commented 8 years ago

It'd be nice to use JavaScript everywhere, f.e.:

    constructor(props) {
        super(props)

        this.mapContainerElement = React.createClass(
            render() {
                return (
                    <Node ref="mapNode" position={[0,0,0]}>
                    </Node>
                )
            },
        )
        this.bigGpsButtonElement = React.createClass(
            render() {
                return (
                    <Button ref="bigGpsButton">
                    </Button>
                )
            },
        )
    }

    /**
     * Renders the default mapContainerElement and bigGpsButtonElement.
     */
    render() {
        return (
            <Node _famousParent={this}>
                <this.mapContainerElement ref="mapContainerElement" />
                <this.bigGpsButtonElement ref="bigGpsButtonElement" />
            </Node>
        )
    }

Note the use of this in the render function. That makes sense. If we can put a normal variable reference there, we should likewise be able to use an object reference.

trusktr commented 8 years ago

Nevermind, it seems that you can. I forgot the curlies in the React.createClass( calls. :blush: