import * as React from 'react'; import Component from 'react-component-component'; import { debounce } from 'lodash'; export type THoc = ( InputCompoent: React.ComponentType, ) => React.ComponentType; export const readFile = (file: File): Promise => new Promise((resolve, reject) => { var reader = new FileReader(); reader.readAsText(file, 'UTF-8'); reader.onload = function (evt: any) { resolve(evt.target.result); }; reader.onerror = function (evt) { reject(); }; }); export const withDebouncedOnChange = ({ debounceTime = 500, }: { debounceTime?: number; } = {}) => (Input) => ({ value, onChange, ...props }) => { interface ILocalState { value: string; } interface IStateContainer { state: ILocalState; setState: (s: ILocalState) => void; } const debouncedOnchange = debounce((e: React.SyntheticEvent) => { e.currentTarget = e.target as HTMLInputElement; onChange(e); }, debounceTime); const whenInputChange = (s: IStateContainer) => (e: React.SyntheticEvent) => { e.persist(); s.setState({ value: e.currentTarget.value }); debouncedOnchange(e); }; return ( {(s: IStateContainer) => ( )} ); };