Skip to content

Commit 4dbb2af

Browse files
committed
Improve React HOC example
I decided that `WrappedComponent` is clearer than `Component` here, so I made the switch. I also realized that `WrappedComponent.name` might still be undefined, so I added a fallback value of "Component".
1 parent 1917968 commit 4dbb2af

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

react/README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,23 @@
107107

108108
```jsx
109109
// bad
110-
export default function withFoo(Component) {
110+
export default function withFoo(WrappedComponent) {
111111
return function WithFoo(props) {
112-
return <Component {...props} foo />;
112+
return <WrappedComponent {...props} foo />;
113113
}
114114
}
115115
116116
// good
117-
export default function withFoo(Component) {
117+
export default function withFoo(WrappedComponent) {
118118
function WithFoo(props) {
119-
return <Component {...props} foo />;
119+
return <WrappedComponent {...props} foo />;
120120
}
121121
122-
WithFoo.displayName = `withFoo(${Component.displayName || Component.name})`;
122+
const wrappedComponentName = WrappedComponent.displayName
123+
|| WrappedComponent.name
124+
|| 'Component';
125+
126+
WithFoo.displayName = `withFoo(${wrappedComponentName})`;
123127
return WithFoo;
124128
}
125129
```

0 commit comments

Comments
 (0)