import { RxSubscribe } from "@heydovetail/ui-components"; import React from "react"; import { AttachmentService, AttachmentUpload } from "../../AttachmentService"; import { Attachment } from "../../util/attrs"; // HACK: Should not be necessary in TypeScript 2.9 class RxSubscribeUploadState extends RxSubscribe {} export interface Props { attachmentService: AttachmentService; attachment: Attachment; children: (preview: AttachmentUpload) => React.ReactNode; } export interface State { observable: ReturnType; } export class AttachmentUploadSubscribe 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.getUploadState(props.attachment.id) }; }