Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "React.React = React" #3221

Closed
wants to merge 1 commit into from
Closed

Add "React.React = React" #3221

wants to merge 1 commit into from

Conversation

zertosh
Copy link
Member

@zertosh zertosh commented Feb 21, 2015

Lets people do this: var {React, PropTypes} = require('react');.

@zpao Is it too late to make it into v0.13?

@sebmarkbage
Copy link
Collaborator

Why not just destructure other properties such as createClass as well?

var {createClass, PropTypes} = require('react');

@zertosh
Copy link
Member Author

zertosh commented Feb 22, 2015

@sebmarkbage Because React needs to be in scope for JSX's React.createElement and React.__spead

@zertosh
Copy link
Member Author

zertosh commented Feb 22, 2015

Oh and the displayName transform also depends on explicitly calling React.createClass
https://github.com/facebook/react/blob/5ab7fde/vendor/fbtransform/transforms/reactDisplayName.js#L20-L22

@chicoxyzzy
Copy link
Contributor

this can be done by

let React = require('react');
let { PropTypes, createClass } = React;

or even

import React, {propTypes} from 'react';

@zertosh
Copy link
Member Author

zertosh commented Feb 23, 2015

@chicoxyzzy This change is for convenience. So two variable declaration statements kinda negates the point - that's what I do now anyway. And, the import works with babel but not with jstransform.

@vjeux
Copy link
Contributor

vjeux commented Feb 25, 2015

FYI, on react native, the convention we adopted is

var React = require('react-native');
var {
  Image,
  StyleSheet,
  Text,
  View,
  ix,
} = React;

@zertosh
Copy link
Member Author

zertosh commented Feb 25, 2015

@vjeux if the pattern is pretty established, then I can close this out

@zpao
Copy link
Member

zpao commented Feb 25, 2015

I talked with @sebmarkbage yesterday. Basically, we netted out that this is going to be a larger issue as we move into a world where more people are using destructuring and ES6 modules. It's slightly inconvenient to do this across 2 statements, but it's also weird to create circular references to save a line of code. It's unfortunate that our own transforms depend on React being in scope but that's where we are for now.

Let's leave it as is for now and if a widespread pattern (which might just be what you proposed) shakes out soon, we'll look at adopting it.

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

Successfully merging this pull request may close these issues.

5 participants