I am trying to change value of input field based on another one and vice versa.
That's create issue, any changed value not displayed in input. Anything I type is not show by input field.
Following which I tried, You can see I am trying to change value of input 1 based on 2 and 2nd input value based on first:
import React, { useState, useEffect } from 'react';
const App = () => {
useEffect(() => {
//fetch api call here
});
const [firstVal, setFirstVal] = useState(0);
const [secondVal, setSecondVal] = useState(0);
const changeFirstValue = (e) => {
setSecondVal(e.target.value / 2);
}
const changeSecondValue = (e) => {
setFirstVal(e.target.value * 2);
}
return (
<div>
<input type='number' value={firstVal} onChange={changeFirstValue}></input>
<input type='number' value={secondVal} onChange={changeSecondValue}></input>
</div>
)
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
Any help would be greatly appreciated.