mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
"Don't Mutate the Original Component" example and description mismatch (#8695)
(cherry picked from commit df0d2a5106)
This commit is contained in:
committed by
Dan Abramov
parent
5cdd66700b
commit
2bbf07b25e
@@ -188,7 +188,7 @@ function logProps(InputComponent) {
|
||||
const EnhancedComponent = logProps(InputComponent);
|
||||
```
|
||||
|
||||
There are a few problems with this. One is that the input component cannot be reused separately from the enhanced component. More crucially, if you apply another HOC to `EnhancedComponent` that *also* mutates `shouldComponentUpdate`, the first HOC's functionality will be overridden! This HOC also won't work with function components, which do not have lifecycle methods.
|
||||
There are a few problems with this. One is that the input component cannot be reused separately from the enhanced component. More crucially, if you apply another HOC to `EnhancedComponent` that *also* mutates `componentWillReceiveProps`, the first HOC's functionality will be overridden! This HOC also won't work with function components, which do not have lifecycle methods.
|
||||
|
||||
Mutating HOCs are a leaky abstraction—the consumer must know how they are implemented in order to avoid conflicts with other HOCs.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user