mirror of
https://github.com/facebookarchive/prepack.git
synced 2024-10-27 07:41:52 +03:00
8264cfffd7
Summary: Release notes: Adds`createRef` and `forwardRef` to the React compiler This PR adds both features from React 16.3, including full inlining of forwardRef functions. Closes https://github.com/facebook/prepack/pull/1731 Differential Revision: D7599780 Pulled By: trueadm fbshipit-source-id: 50458546c7a4374baea7fa80feb21262dd5692af
32 lines
772 B
JavaScript
32 lines
772 B
JavaScript
var React = require('react');
|
|
// the JSX transform converts to React, so we need to add it back in
|
|
this['React'] = React;
|
|
|
|
function Child(props) {
|
|
return <div ref={props.forwardedRef} />;
|
|
}
|
|
|
|
const WrappedComponent = React.forwardRef((props, ref) => {
|
|
return <Child {...props} forwardedRef={ref} />;
|
|
});
|
|
|
|
function App(props) {
|
|
return (
|
|
<WrappedComponent ref={props.x} />
|
|
);
|
|
}
|
|
|
|
App.getTrials = function(renderer, Root) {
|
|
let results = [];
|
|
var refValue = null;
|
|
renderer.update(<Root x={val => refValue = val} />);
|
|
results.push(['simple render with refs', renderer.toJSON()]);
|
|
results.push(['ref node is of div', refValue.type]);
|
|
return results;
|
|
};
|
|
|
|
if (this.__optimizeReactComponentTree) {
|
|
__optimizeReactComponentTree(App);
|
|
}
|
|
|
|
module.exports = App; |