streamich / libreact

Collection of useful React components
The Unlicense
2.63k stars 81 forks source link

[Question] How to use withViewport with withRouter ? #16

Closed rockmandash closed 6 years ago

rockmandash commented 6 years ago

Hello, thank you for this amazing library. I have a component like this

export default withViewport(MyComponent, 'visible', {
  threshold: 0.25
});

Normaly with HOCs I will do this

export default compose(withViewport, withRouter)(MyComponent)

But I have threshold parameters! How do I pass in? Thank you!

streamich commented 6 years ago

You can wrap the withViewport HOC into your custom one.

const withMyViewport = (Comp) => withViewport(Comp, 'visible', {threshold: 0.25});

And then use your new HOC.

export default compose(withMyViewport, withRouter)(MyComponent)

Hope that woks.

rockmandash commented 6 years ago

@streamich for your reply!