import * as React from "react"; type RenderT = ( state: State, update: (key: K, value: State[K]) => void, ) => React.ReactNode; interface Props { state: State; render: RenderT; } export function StorybookOneWayBinding(props: Props) { const C = StorybookOneWayBinding_ as any; return ; } class StorybookOneWayBinding_ extends React.Component, State> { state: State = this.getState(this.props); getState(props: Props): State { return props.state; } componentWillReceiveProps(nextProps: Readonly>) { const nextState = this.getState(nextProps); for (let key_ of Object.keys(nextState)) { const key = key_ as keyof State; if (nextProps.state[key] !== nextState[key]) { this.setState((): any => { return { [key]: nextProps.state[key], }; }); } } } update = (key: K, value: State[K]) => { this.setState((): any => { return { [key]: value, }; }); }; render() { const { render } = this.props; return render(this.state, this.update); } }