Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. # Concerns
  2.  
  3. ## React Dev Tools
  4. Any wrapped components will be rendered into the React dev tools with their wrappers intact. This becomes pretty invasive when most of your components are using a HOC wrapper.
  5.  
  6. Here's a workaround for defining HOCs that respect stateless functional components and don't render a wrapper.
  7.  
  8. ```js
  9. function withName(Component) {
  10. class EnhancedComponent extends React.Component {
  11. render() {
  12. return Component(this.props, this.context);
  13. }
  14. }
  15.  
  16. EnhancedComponent.displayName = Component.displayName || Component.name;
  17. }
  18. ```
  19.  
  20. This way, the actual `<Component>` doesn't end up in the React tree. However, it only works for stateless components.
  21.  
  22. ## Shallow Rendering
  23. Shallow rendering doesn't work with components that are wrapped by HOC components.
  24.  
  25. ```
  26. shallow(<div><h1>Hi</h1></div>)
  27. // => <div><h1>Hi</h1></div>
  28.  
  29. let Counter = connect(Counter)
  30. shallow(Counter)
  31. // => <Connected />
  32. ```
  33.  
  34. To keep components testable without enforcing the container/presentational divide, wrapped components need to be squashed and kept stateless.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement