N
N
Norwood2021-02-28 15:35:08
React
Norwood, 2021-02-28 15:35:08

React currency converter. Where to implement the recalculation function?

I am making a currency converter. There are 2 inputs. When you enter a number in the first input, the result should automatically be displayed in the second input and vice versa, if you enter in the second, the result is displayed in the first. 603b8cda80781066347197.jpeg
I made the display of the input number in the input and display it in the second input, but where can I implement the recalculation of the input number?

class Form extends React.Component{
  state={
    firstValue:'',
    secondValue:'',
  }
  handleChange =(event)=>{
    this.setState({firstValue:event.target.value,secondValue: event.target.value},
      );
  }
  render() {
    const {firstValue, secondValue}= this.state;
    console.log(firstValue)

    return<div>
      <input type="number" name='firstValue' value={this.state.secondValue} onChange={this.handleChange}/>
      <input type="number" name='secondValue' value={this.state.firstValue} onChange={this.handleChange}/>
    </div>
  }
}
export default Form;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-02-28
@0xD34F

https://jsfiddle.net/3h8zfw2k/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question