trainline / react-skeletor

Skeleton loading for React
https://trainline.github.io/react-skeletor/
Other
554 stars 27 forks source link

Connector API to access isPending #11

Open SamyPesse opened 6 years ago

SamyPesse commented 6 years ago

I'm starting to use react-skeletor, and I'm missing something in the API: a connector to access the isPending and have my own logic of rendering, for example a component to render an avatar:

import { connectSkeleton } from '@trainline/react-skeletor';

@connectSkeleton(({ isPending }) => ({
    isPending
})
class Avatar extends React.Component {
    render() {
         const { isPending } = this.props;

         return isPending ? <div></div> : <a href="...">...</a>
    }
}

Currently, I can directly use contextTypes and get the skeleton context, but this is a not recommended API by React.

At some point, it may requires a subscribing schema in the context instead of storing the values directly.

Will you be willing to accept a connectSkeleton API ? (I can make a PR)

alex3165 commented 6 years ago

Hi @SamyPesse, glad to hear you are using react-skeletor. I think you can write your own HOC and access the context, that is what a connectSkeleton HOC would do anyway. React forbid the use of context if you don't really know what you are doing and think of using context to replace props which is wrong in 90% of the cases.