-
Notifications
You must be signed in to change notification settings - Fork 58
CPLAT-9327 Improve forwardRef documentation, add displayName argument #454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
smaifullerton-wk
merged 6 commits into
function-components-wip
from
improve-forwardref-documentation
Jul 29, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e5f8e78
Allow displayName to be passed to forwardRef
aaronlademann-wf 9c8825e
Improve / add forwardRef examples
aaronlademann-wf 50c6b57
Resolve merge conflicts with master, update boilerplate in documentat…
smaifullerton-wk 6ca4f3b
Consume react ^5.4.0
smaifullerton-wk 36eff3b
Merge 'upstream/function-components-wip' into improve-forwardref-docu…
aaronlademann-wf 04b7b2c
Update built files
smaifullerton-wk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import 'package:over_react/over_react.dart'; | ||
|
||
// ignore: uri_has_not_been_generated | ||
part 'forward_ref.over_react.g.dart'; | ||
|
||
final FancyButton = forwardRef<DomProps>((props, ref) { | ||
final classes = ClassNameBuilder.fromProps(props) | ||
..add('FancyButton'); | ||
|
||
return (Dom.button() | ||
..addProps(getPropsToForward(props, onlyCopyDomProps: true)) | ||
..className = classes.toClassName() | ||
..ref = ref | ||
)('Click me!'); | ||
}, displayName: 'FancyButton')(Dom.button); | ||
|
||
final LogProps = forwardRef<LogPropsProps>((props, ref) { | ||
return (_LogProps() | ||
..addProps(props) | ||
.._forwardedRef = ref | ||
)('Click me!'); | ||
}, displayName: 'LogProps')(_LogProps); | ||
|
||
@Factory() | ||
UiFactory<LogPropsProps> _LogProps = _$_LogProps; | ||
|
||
@Props() | ||
class _$LogPropsProps extends UiProps { | ||
BuilderOnlyUiFactory<DomProps> builder; | ||
|
||
// Private since we only use this to pass along the value of `ref` to | ||
// the return value of forwardRef. | ||
// | ||
// Consumers can set this private field value using the public `ref` setter. | ||
Ref _forwardedRef; | ||
} | ||
|
||
@Component2() | ||
class LogPropsComponent extends UiComponent2<LogPropsProps> { | ||
@override | ||
void componentDidUpdate(Map prevProps, _, [__]) { | ||
print('old props: $prevProps'); | ||
print('new props: $props'); | ||
} | ||
|
||
@override | ||
render() { | ||
return (props.builder() | ||
..modifyProps(addUnconsumedDomProps) | ||
..ref = props._forwardedRef | ||
)(props.children); | ||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please double check the boilerplate here - I updated this example from what it was previously.