Skip to content

Instantly share code, notes, and snippets.

@scink
Last active February 13, 2019 08:46
Show Gist options
  • Save scink/689da03059c5a3eaf5fcb258db176dda to your computer and use it in GitHub Desktop.
Save scink/689da03059c5a3eaf5fcb258db176dda to your computer and use it in GitHub Desktop.
export type Item = {
name: string;
value: string;
};
export type FooProps = {
data: RemoteData<Error, Item[]>;
};
const RenderRemoteData = getRenderRemoteData({
DataStateFailure: () => <span>Failure</span>,
DataStateNoData: () => <span>NoData</span>,
DataStatePending: () => <span>Pending</span>,
});
export class Foo extends PureComponent<FooProps> {
public render() {
const { data } = this.props;
// this option has an error
return <RenderRemoteData data={data} success={this.renderSuccess} noData={isEmpty} />;
// but this one does not
// return <RenderRemoteData data={data} success={this.renderSuccess} noData={data => isEmpty(data)} />;
}
private renderSuccess = (data: Item[]) => (
<Fragment>
{data.map(item => (
<span>{item.name}</span>
))}
</Fragment>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment