Toggle withRouter HOC

Either unwraps or wraps your component with withRouter from react-router-dom.

If your component is not wrapped, it will be. If it is, it won't be. It's compatible with React Router 4.

How it works

When wrapping
  • Adds withRouter import statement
  • Wraps exported reference with withRouter call
When unwrapping
  • Strips exported reference out of withRouter call
  • Removes withRouter import statement

Works with

  • Functional components defined as an arrow function
  • Functional components defined as a function
  • Class components
  • Higher order functional components defined as an arrow function
  • Higher order functional components defined as a function
  • Higher order class components

Examples

© 2018 - 2019 Kamil Mielnik & Yuriy Yakym. All rights reserved.