Skip to content

Add "React.React = React"#3221

Closed
zertosh wants to merge 1 commit into
react:masterfrom
zertosh:react-react
Closed

Add "React.React = React"#3221
zertosh wants to merge 1 commit into
react:masterfrom
zertosh:react-react

Conversation

@zertosh

@zertosh zertosh commented Feb 21, 2015

Copy link
Copy Markdown
Contributor

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

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

@sebmarkbage

Copy link
Copy Markdown
Contributor

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

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

@zertosh

zertosh commented Feb 22, 2015

Copy link
Copy Markdown
Contributor Author

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

@zertosh

zertosh commented Feb 22, 2015

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
Contributor

this can be done by

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

or even

import React, {propTypes} from 'react';

@zertosh

zertosh commented Feb 23, 2015

Copy link
Copy Markdown
Contributor Author

@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

vjeux commented Feb 25, 2015

Copy link
Copy Markdown
Contributor

FYI, on react native, the convention we adopted is

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

@zertosh

zertosh commented Feb 25, 2015

Copy link
Copy Markdown
Contributor Author

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

@zpao

zpao commented Feb 25, 2015

Copy link
Copy Markdown
Contributor

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