import React, {Component} from "react"; import {Tip} from "./Tip"; class Switch extends Component { constructor(props) { super(props); // Initialize the state object with the initial values from the props this.state = { checked: props.outvar in props.data ? !!(props.data[props.outvar]) : !!(props.fallback) }; // Bind the event handler to this this.handleClick = this.handleClick.bind(this); this.props.target.construct(this.props.outvar, this.state.checked); } handleClick() { // Update the state object with the new value for outvar let new_checked = !this.state.checked; this.setState({ checked: new_checked }); this.props.target.update(this.props.outvar, new_checked); } render() { let key = this.props.id + this.props.outvar; return (