Skip to content
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

forwarding-refs: concrete example for function name #1832

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion content/docs/forwarding-refs.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ For example, the following component will appear as "*ForwardRef*" in the DevToo

`embed:forwarding-refs/wrapped-component.js`

If you name the render function, DevTools will also include its name (e.g. "*ForwardRef(myFunction)*"):
If you name the render function, DevTools will also include its name (e.g. "*ForwardRef(Button)*"):

`embed:forwarding-refs/wrapped-component-with-function-name.js`

Expand Down
15 changes: 10 additions & 5 deletions examples/forwarding-refs/wrapped-component-with-function-name.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const WrappedComponent = React.forwardRef(
function myFunction(props, ref) {
return <LogProps {...props} forwardedRef={ref} />;
}
);
const FancyButton = React.forwardRef(function Button(
props,
ref
) {
return (
<button ref={ref} className="FancyButton">
{props.children}
</button>
);
});
8 changes: 6 additions & 2 deletions examples/forwarding-refs/wrapped-component.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const WrappedComponent = React.forwardRef((props, ref) => {
return <LogProps {...props} forwardedRef={ref} />;
const FancyButton = React.forwardRef((props, ref) => {
return (
<button ref={ref} className="FancyButton">
{props.children}
</button>
);
});