fkhadra / react-on-screen

Check if a react component in the viewport
https://fkhadra.github.io/react-on-screen/
MIT License
405 stars 50 forks source link

Any chance for an HOC? #36

Open nharlow89 opened 5 years ago

nharlow89 commented 5 years ago

I would like to express interest in adding an optional HOC container to this package. Not really an issue necessarily, but I seem to be composing components with one or more HOC these days and it might help this library fit it with common design patterns.

futpib commented 5 years ago

Had to adapt this into a HOC:

import React from 'react';
import TrackVisibility from 'react-on-screen';

export default (Component, visibilityProps = {}) => props => (
    <TrackVisibility partialVisibility {...visibilityProps}>
        {({ isVisible }) => (
            <Component
                {...props}
                isVisible={isVisible}
            />
        )}
    </TrackVisibility>
);