Thursday, October 12, 2017

React 16 now allows rendering with no root element

This code:
    render() {
        return (
            <div>
                <h1>Hello world!</h1>
                <div>Welcome to hot-reloading React written in TypeScript! {this.state.count}</div>
            </div>
        );
    }


Can now be rendered without the root element (e.g., div) in React 16:
    render() {
        return ([
                <h1>Hello world!</h1>,
                <div>Welcome to hot-reloading React written in TypeScript! {this.state.count}</div>

        ]);
    }


Note the use of array above. This isn't allowed yet though:







Happy Coding!

No comments:

Post a Comment