prepack/test/react/functional-components/refs3.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

46 lines
1.0 KiB
JavaScript

var React = require('react');
// the JSX transform converts to React, so we need to add it back in
this['React'] = React;
class ClassComponent extends React.Component {
constructor() {
super();
this.state = {};
}
getValue() {
return this.props.value;
}
render() {
return <div />;
}
}
function Child(props) {
return <ClassComponent ref={props.forwardedRef} value={props.value} />;
}
const WrappedComponent = React.forwardRef((props, ref) => {
return <Child {...props} forwardedRef={ref} />;
});
function App(props) {
return (
<WrappedComponent {...props} ref={props.x} />
);
}
App.getTrials = function(renderer, Root) {
let results = [];
var ref = React.createRef();
var value = "Hello world!!!";
renderer.update(<Root x={ref} value={value} />);
results.push(['simple render with refs', renderer.toJSON()]);
results.push(['ref node is a method of the class', ref.current.getValue()]);
return results;
};
if (this.__optimizeReactComponentTree) {
__optimizeReactComponentTree(App);
}
module.exports = App;