Skip to content

Commit 2e1554d

Browse files
committed
Adopt bvaughn's example
1 parent c72935a commit 2e1554d

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

examples/16-3-release-blog-post/forward-ref-example.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,21 @@ function withTheme(Component) {
2020
// We can pass it along to ThemedComponent as a regular prop, e.g. "forwardedRef"
2121
// And it can then be attached to the Component.
2222
// highlight-range{1-3}
23-
return React.forwardRef((props, ref) => (
24-
<ThemedComponent {...props} forwardedRef={ref} />
25-
));
23+
function refForwarder(props, ref) {
24+
return (
25+
<ThemedComponent {...props} forwardedRef={ref} />
26+
);
27+
}
28+
29+
// These next lines are not necessary,
30+
// But they do give the component a better display name in DevTools,
31+
// e.g. "ForwardRef(withTheme(MyComponent))"
32+
// highlight-range{1-2}
33+
const name = Component.displayName || Component.name;
34+
refForwarder.displayName = `withTheme(${name})`;
35+
36+
// highlight-next-line
37+
return React.forwardRef(refForwarder);
2638
}
2739

2840
// highlight-next-line

0 commit comments

Comments
 (0)