reactjs/react-future

Killing React.createElement

iddan opened this issue · 1 comments

iddan commented

Problem

import React from 'react';
React.createElement();

Solution

Add to ReactDOM.render() and AppRegistry.registerComponent():

function prerender (tempalte) {
    if (typeof template !== 'object') {
        return template;
    }
    let { props: { children }} = template;
    delete template.props.children;
    return React.createElement(template.type, template.props, template.children.map(child => prerender(child)));
   
}

and

<div className="card">
    <span>hello</span>
</div>

will become

({
    type: 'div',
    props: {
        className: 'card',
        children: [
            {
                type: 'span',
                children: 'hello'
            }
        ]
    }
})

Why

  • The importance of semantic markup
  • React should not be a dev dependency for small modules it takes too much time to use. More than that if PropTypes will go native now no imports at all except for helpers!!!

We don't have plans to do this. React elements are already more or less plain objects, but we intentionally add a symbol $$typeof which allows us to verify that it did not come directly from a JSON blob:

facebook/react#3473

This fixes a security hole.

React should not be a dev dependency for small modules it takes too much time to use. More than that if PropTypes will go native now no imports at all except for helpers!!!

React itself is a quite small package. In the future we might split out PropTypes and createClass. If you want, you can use babel-plugin-react-inline-elements which makes it so JSX has no dependency on the React package in prod.