Skip to content

Commit d4b9f35

Browse files
committed
[change] createElement -> unstable_createElement
Rename the 'createElement' export to reflect its unstable status. Fix #1385
1 parent 3ac0b96 commit d4b9f35

File tree

12 files changed

+38
-34
lines changed

12 files changed

+38
-34
lines changed

docs/guides/advanced.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Use with existing React DOM components
44

5-
React Native for Web exports a web-specific module called `createElement`,
5+
React Native for Web exports a web-specific module called `unstable_createElement`,
66
which can be used to wrap React DOM components. This allows you to use React
77
Native's accessibility and style optimizations.
88

@@ -11,19 +11,19 @@ In the example below, `Video` will now accept common React Native props such as
1111
props.
1212

1313
```js
14-
import { createElement } from 'react-native-web';
15-
const Video = (props) => createElement('video', props);
14+
import { unstable_createElement } from 'react-native-web';
15+
const Video = (props) => unstable_createElement('video', props);
1616
```
1717

1818
This also works with composite components defined in your existing component
1919
gallery or dependencies ([live example](https://www.webpackbin.com/bins/-KiTSGFw3fB9Szg7quLI)).
2020

2121
```js
2222
import RaisedButton from 'material-ui/RaisedButton';
23-
import { createElement } from 'react-native-web';
23+
import { unstable_createElement } from 'react-native-web';
2424
import { StyleSheet } from 'react-native';
2525

26-
const CustomButton = (props) => createElement(RaisedButton, {
26+
const CustomButton = (props) => unstable_createElement(RaisedButton, {
2727
...props,
2828
style: [ styles.button, props.style ]
2929
});
@@ -35,11 +35,11 @@ const styles = StyleSheet.create({
3535
});
3636
```
3737

38-
And `createElement` can be used as drop-in replacement for `React.createElement`:
38+
And `unstable_createElement` can be used as drop-in replacement for `React.createElement`:
3939

4040
```js
41-
/* @jsx createElement */
42-
import { createElement } from 'react-native-web';
41+
/* @jsx unstable_createElement */
42+
import { unstable_createElement } from 'react-native-web';
4343
const Video = (props) => <video {...props} style={[ { marginVertical: 10 }, props.style ]} />
4444
```
4545

@@ -55,7 +55,7 @@ an API inspired by styled-components ([live
5555
example](https://www.webpackbin.com/bins/-KjT9ziwv4O7FDZdvsnX)).
5656

5757
```js
58-
import { createElement } from 'react-native-web';
58+
import { unstable_createElement } from 'react-native-web';
5959
import { StyleSheet } from 'react-native';
6060

6161
/**
@@ -78,7 +78,7 @@ const styled = (Component, styler) => {
7878

7979
return (
8080
isDOMComponent
81-
? createElement(Component, nextProps)
81+
? unstable_createElement(Component, nextProps)
8282
: <Component {...nextProps} />
8383
);
8484
}

packages/babel-plugin-react-native-web/src/__tests__/__snapshots__/index-test.js.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@
33
exports[`Rewrite react-native to react-native-web export from "react-native": export from "react-native" 1`] = `
44
"
55
export { View } from 'react-native';
6-
export { ColorPropType, StyleSheet, Text, createElement } from 'react-native';
6+
export { ColorPropType, StyleSheet, Text, unstable_createElement } from 'react-native';
77
88
↓ ↓ ↓ ↓ ↓ ↓
99
1010
export { default as View } from 'react-native-web/dist/exports/View';
1111
export { default as ColorPropType } from 'react-native-web/dist/exports/ColorPropType';
1212
export { default as StyleSheet } from 'react-native-web/dist/exports/StyleSheet';
1313
export { default as Text } from 'react-native-web/dist/exports/Text';
14-
export { default as createElement } from 'react-native-web/dist/exports/createElement';
14+
export { default as unstable_createElement } from 'react-native-web/dist/exports/createElement';
1515
"
1616
`;
1717

1818
exports[`Rewrite react-native to react-native-web export from "react-native-web": export from "react-native-web" 1`] = `
1919
"
2020
export { View } from 'react-native-web';
21-
export { ColorPropType, StyleSheet, Text, createElement } from 'react-native-web';
21+
export { ColorPropType, StyleSheet, Text, unstable_createElement } from 'react-native-web';
2222
2323
↓ ↓ ↓ ↓ ↓ ↓
2424
2525
export { default as View } from 'react-native-web/dist/exports/View';
2626
export { default as ColorPropType } from 'react-native-web/dist/exports/ColorPropType';
2727
export { default as StyleSheet } from 'react-native-web/dist/exports/StyleSheet';
2828
export { default as Text } from 'react-native-web/dist/exports/Text';
29-
export { default as createElement } from 'react-native-web/dist/exports/createElement';
29+
export { default as unstable_createElement } from 'react-native-web/dist/exports/createElement';
3030
"
3131
`;
3232

@@ -68,13 +68,13 @@ import * as ReactNativeModules from 'react-native-web/dist/cjs/index';
6868

6969
exports[`Rewrite react-native to react-native-web import from "react-native-web": import from "react-native-web" 1`] = `
7070
"
71-
import { createElement } from 'react-native-web';
71+
import { unstable_createElement } from 'react-native-web';
7272
import { ColorPropType, StyleSheet, View, TouchableOpacity, processColor } from 'react-native-web';
7373
import * as ReactNativeModules from 'react-native-web';
7474
7575
↓ ↓ ↓ ↓ ↓ ↓
7676
77-
import createElement from 'react-native-web/dist/exports/createElement';
77+
import unstable_createElement from 'react-native-web/dist/exports/createElement';
7878
import ColorPropType from 'react-native-web/dist/exports/ColorPropType';
7979
import StyleSheet from 'react-native-web/dist/exports/StyleSheet';
8080
import View from 'react-native-web/dist/exports/View';
@@ -123,14 +123,14 @@ const TouchableOpacity = require('react-native-web/dist/cjs/exports/TouchableOpa
123123
exports[`Rewrite react-native to react-native-web require "react-native-web": require "react-native-web" 1`] = `
124124
"
125125
const ReactNative = require('react-native-web');
126-
const { createElement } = require('react-native-web');
126+
const { unstable_createElement } = require('react-native-web');
127127
const { ColorPropType, StyleSheet, View, TouchableOpacity, processColor } = require('react-native-web');
128128
129129
↓ ↓ ↓ ↓ ↓ ↓
130130
131131
const ReactNative = require('react-native-web/dist/index');
132132
133-
const createElement = require('react-native-web/dist/exports/createElement').default;
133+
const unstable_createElement = require('react-native-web/dist/exports/createElement').default;
134134
135135
const ColorPropType = require('react-native-web/dist/exports/ColorPropType').default;
136136

packages/babel-plugin-react-native-web/src/__tests__/index-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ import * as ReactNativeModules from 'react-native';`,
2222
},
2323
{
2424
title: 'import from "react-native-web"',
25-
code: `import { createElement } from 'react-native-web';
25+
code: `import { unstable_createElement } from 'react-native-web';
2626
import { ColorPropType, StyleSheet, View, TouchableOpacity, processColor } from 'react-native-web';
2727
import * as ReactNativeModules from 'react-native-web';`,
2828
snapshot: true
2929
},
3030
{
3131
title: 'export from "react-native"',
3232
code: `export { View } from 'react-native';
33-
export { ColorPropType, StyleSheet, Text, createElement } from 'react-native';`,
33+
export { ColorPropType, StyleSheet, Text, unstable_createElement } from 'react-native';`,
3434
snapshot: true
3535
},
3636
{
3737
title: 'export from "react-native-web"',
3838
code: `export { View } from 'react-native-web';
39-
export { ColorPropType, StyleSheet, Text, createElement } from 'react-native-web';`,
39+
export { ColorPropType, StyleSheet, Text, unstable_createElement } from 'react-native-web';`,
4040
snapshot: true
4141
},
4242
{
@@ -57,7 +57,7 @@ const { StyleSheet, TouchableOpacity } = require('react-native');`,
5757
{
5858
title: 'require "react-native-web"',
5959
code: `const ReactNative = require('react-native-web');
60-
const { createElement } = require('react-native-web');
60+
const { unstable_createElement } = require('react-native-web');
6161
const { ColorPropType, StyleSheet, View, TouchableOpacity, processColor } = require('react-native-web');`,
6262
snapshot: true
6363
}

packages/babel-plugin-react-native-web/src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ const isCommonJS = opts => opts.commonjs === true;
44

55
const getDistLocation = (importName, opts) => {
66
const format = isCommonJS(opts) ? 'cjs/' : '';
7-
if (importName === 'index') {
7+
const internalName = importName === 'unstable_createElement' ? 'createElement' : importName;
8+
if (internalName === 'index') {
89
return `react-native-web/dist/${format}index`;
9-
} else if (importName && moduleMap[importName]) {
10-
return `react-native-web/dist/${format}exports/${importName}`;
10+
} else if (internalName && moduleMap[internalName]) {
11+
return `react-native-web/dist/${format}exports/${internalName}`;
1112
}
1213
};
1314

packages/benchmarks/src/app/Icons.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Fragment } from 'react';
2-
import { createElement, StyleSheet, Text } from 'react-native';
2+
import { unstable_createElement as createElement, StyleSheet, Text } from 'react-native';
33

44
const styles = StyleSheet.create({
55
root: {
@@ -18,7 +18,10 @@ const createIcon = children => {
1818
createElement(
1919
'svg',
2020
{
21-
style: StyleSheet.compose(styles.root, props.style),
21+
style: StyleSheet.compose(
22+
styles.root,
23+
props.style
24+
),
2225
width: 24,
2326
height: 24,
2427
viewBox: '0 0 24 24'

packages/benchmarks/src/implementations/react-native-web/Dot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable react/prop-types */
2-
import { createElement, StyleSheet } from 'react-native';
2+
import { unstable_createElement as createElement, StyleSheet } from 'react-native';
33

44
const Dot = ({ size, x, y, children, color }) =>
55
createElement('div', {

packages/benchmarks/src/implementations/react-native-web/Tweet/IconDirectMessage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable react/prop-types */
2-
import { createElement } from 'react-native';
2+
import { unstable_createElement as createElement } from 'react-native';
33
import React from 'react';
44
import styles from './styles';
55

packages/benchmarks/src/implementations/react-native-web/Tweet/IconHeart.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable react/prop-types */
2-
import { createElement } from 'react-native';
2+
import { unstable_createElement as createElement } from 'react-native';
33
import React from 'react';
44
import styles from './styles';
55

packages/benchmarks/src/implementations/react-native-web/Tweet/IconReply.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable react/prop-types */
2-
import { createElement } from 'react-native';
2+
import { unstable_createElement as createElement } from 'react-native';
33
import React from 'react';
44
import styles from './styles';
55

packages/benchmarks/src/implementations/react-native-web/Tweet/IconRetweet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable react/prop-types */
2-
import { createElement } from 'react-native';
2+
import { unstable_createElement as createElement } from 'react-native';
33
import React from 'react';
44
import styles from './styles';
55

packages/react-native-web/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ import DeviceEventEmitter from './exports/DeviceEventEmitter';
8282

8383
export {
8484
// top-level API
85-
createElement,
85+
createElement as unstable_createElement,
8686
findNodeHandle,
8787
render,
8888
unmountComponentAtNode,

packages/website/storybook/ui-explorer/Code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @flow
33
*/
44

5-
import { createElement, StyleSheet } from 'react-native';
5+
import { unstable_createElement as createElement, StyleSheet } from 'react-native';
66

77
const Code = props => createElement('code', { ...props, style: [styles.code, props.style] });
88

0 commit comments

Comments
 (0)