class MoneyInput extends React.Component { constructor(props) { super(props); this.handleChange = this.handleChange.bind(this); } handleChange(e) { this.props.onMoneyChange(e.target.value); } render() { const amount = this.props.amount?parseFloat(this.props.amount).toFixed(2):0; const currency = this.props.currency; return (
Enter amount of money in {currency}:
); }}class CurrencyConverter extends React.Component { constructor(props) { super(props); this.handleUSDChange = this.handleUSDChange.bind(this); this.handleEURChange = this.handleEURChange.bind(this); this.state = {amount: '', currency: 'USD'}; } handleUSDChange(amount) { console.log(amount); this.setState({currency: 'USD', amount}); } handleEURChange(amount) { this.setState({currency: 'EUR', amount}); } render() { const currency = this.state.currency; const amount = this.state.amount; const usd = currency === 'EUR' ? (amount * 1.2) : amount; const eur = currency === 'USD' ? (amount / 1.2) : amount; return (
); }}ReactDOM.render(, document.querySelector('div'));