Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.

Killing React.createElement #49

Closed
iddan opened this issue Dec 15, 2016 · 1 comment
Closed

Killing React.createElement #49

iddan opened this issue Dec 15, 2016 · 1 comment

Comments

@iddan
Copy link

iddan commented Dec 15, 2016

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!!!
@sophiebits
Copy link
Member

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants