react-skeletor icon indicating copy to clipboard operation
react-skeletor copied to clipboard

Connector API to access isPending

Open SamyPesse opened this issue 7 years ago • 1 comments

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)

SamyPesse avatar Jan 15 '18 11:01 SamyPesse

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.

alex3165 avatar Jan 16 '18 08:01 alex3165