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

React Native only supports JSX #144

Closed
ColinEberhardt opened this issue Mar 12, 2015 · 6 comments
Closed

React Native only supports JSX #144

ColinEberhardt opened this issue Mar 12, 2015 · 6 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@ColinEberhardt
Copy link

Unless I am mistake, I should be able to substitute this:

return <Text style={styles.text}>Hello World!</Text>;

With this:

return React.createElement('Text', { style: styles.text }, 'Hello World!');

However, the above causes the application to fail as follows:

[native code]
global code
 URL: http://localhost:8081/Examples/PropertyFinder/PropertyFinderApp.includeRequire.runModule.bundle
 line: 5745
 message: null is not a function (evaluating 'autoGenerateWrapperClass(tag)')"
@vjeux
Copy link
Contributor

vjeux commented Mar 12, 2015

Can you try

var Text = React.createFactory(React.Text);
return React.createElement(Text, 'Hello World');

cc @balpert

@ColinEberhardt
Copy link
Author

Arggh .. ignore me, I'm being an idiot. This fails:

return React.createElement('Text', { style: styles.text }, 'Hello World!');

Where Text is passed as a string, but this works:

return React.createElement(Text, { style: styles.text }, 'Hello World!');

@vjeux
Copy link
Contributor

vjeux commented Mar 12, 2015

The error message is still really bad. Would be nice to throw an exception along the lines of 'You tried to render the element 'Text' but it doesn't exist. You can only use string notation for lowercase components'. Want to submit a pull request that warns against this? It would prevent other people from failing into the same mistake

@sophiebits
Copy link
Contributor

We actually don't use or support string-typed components in React native at all. Would be nice to add a warning for non-lowercase components in React core though.

@ColinEberhardt
Copy link
Author

I agree, the error message isn't great. As the react-native behaviour differs from react in this case, one option is to adapt the createElement function, and add the extra parameter type checking here:

https://github.com/facebook/react-native/blob/master/Libraries/ReactIOS/ReactIOS.js#L32

What do you think?

@sophiebits
Copy link
Contributor

In neither case do uppercase tag names make sense, so we can add a warning in React core. We might also want to add some sort of warning for using any string type in React Native.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants