import { RxSubscribe } from "@heydovetail/ui-components"; import React from "react"; import { AttachmentPreview, AttachmentService } from "../../AttachmentService"; import { Attachment } from "../../util/attrs"; // HACK: Should not be necessary in TypeScript 2.9 class RxSubscribeAttachmentPreview extends RxSubscribe {} export interface Props { attachmentService: AttachmentService; attachment: Attachment; children: (preview: AttachmentPreview) => React.ReactNode; } export interface State { observable: ReturnType; } export class AttachmentPreviewSubscribe extends React.Component { public readonly state = stateFromProps(this.props); public render() { const { observable } = this.state; return {this.props.children}; } static getDerivedStateFromProps: React.GetDerivedStateFromProps = nextProps => stateFromProps(nextProps); } function stateFromProps(props: Props): State { return { observable: props.attachmentService.getPreview(props.attachment.id) }; }