import { Component, createRef } from "preact"; export class ToggleableBox extends Component<{ title: string, id: string, checked?: boolean; onChange?: (checked: boolean) => void, }> { inputRef = createRef(); onChangeInternal(newState: boolean) { console.debug(`Changed state of ${this.props.id} to ${newState}`); if (this.props.onChange) { this.props.onChange(newState); } } public forceChange(status: boolean) { if (this.inputRef.current) { let inputElement = this.inputRef.current; inputElement.checked = status; } } render() { return <>
{ this.onChangeInternal(this.inputRef.current.checked); }} />
; } }