prepack/test/react/functional-components/refs2.js
Dominic Gannaway 8264cfffd7 Adds createRef and forwardRef to the React compiler
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
2018-04-12 06:34:44 -07:00

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;