Introduce 'setAndForwardRef' helper function#21823
Closed
empyrical wants to merge 3 commits intofacebook:masterfrom
Closed
Introduce 'setAndForwardRef' helper function#21823empyrical wants to merge 3 commits intofacebook:masterfrom
empyrical wants to merge 3 commits intofacebook:masterfrom
Conversation
analysis-bot
suggested changes
Oct 17, 2018
analysis-bot
left a comment
There was a problem hiding this comment.
Code analysis results:
eslintfound some issues.
facebook-github-bot
approved these changes
Oct 17, 2018
Contributor
facebook-github-bot
left a comment
There was a problem hiding this comment.
TheSavior is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Collaborator
|
@empyrical merged commit d6c8f18 into |
t-nanava
pushed a commit
to microsoft/react-native-macos
that referenced
this pull request
Jun 17, 2019
Summary:
This PR introduces a new helper function called `setAndForwardRef`. It is intended to help with moving components that depend on `NativeMethodsMixin` off of `createReactClass`.
It allows for classes that depend on having a ref to a native component to be able to also forward the native component ref to user code.
Usage is like this:
```js
class MyView extends React.Component {
_nativeRef = null;
_setNativeRef = setAndForwardRef({
getForwardedRef: () => this.props.forwardedRef,
setLocalRef: ref => {
this._nativeRef = ref;
},
});
render() {
return <View ref={this._setNativeRef} />;
}
}
const MyViewWithRef = React.forwardRef((props, ref) => (
<MyView {...props} forwardedRef={ref} />
));
module.exports = MyViewWithRef;
```
Pull Request resolved: facebook#21823
Differential Revision: D10436673
Pulled By: TheSavior
fbshipit-source-id: 32e167bb3ea3234f08d5715168b0e61e4e035a7c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces a new helper function called
setAndForwardRef. It is intended to help with moving components that depend onNativeMethodsMixinoff ofcreateReactClass.It allows for classes that depend on having a ref to a native component to be able to also forward the native component ref to user code.
Usage is like this:
Test Plan:
A new Jest test has been added to
Libraries/Utilities/__tests__/setAndForwardRef-test.jsto put this helper function through its paces.Release Notes:
Help reviewers and the release process by writing your own release notes. See below for an example.
[GENERAL] [ENHANCEMENT] [Libraries/Utilities/tests/setAndForwardRef-test.js] - Added tests for the
setAndForwardRefhelper function[GENERAL] [ENHANCEMENT] [Libraries/Utilities/setAndForwardRef.js] - Added new helper function for forwarding refs inside of class components