I am trying to take multiple input before passing the value to the parent component. The goal is the user would input value in 3 fields and once the user is done and presses the enter key all values are submitted at once and passed to the parent but for some reason it’s only sending value for each individual filed at a time when press entered and it only sets value for that entered field for all input values. Please any help would be appreciated, Thank you in advance!
import React, {useState} from 'react';
import FlowModel from './FlowModel';
const DCF = ({ searchBarText }) => {
const [growthRateInput, setGrowthRateInput] = useState("");
const [perpGrowthRate, setPerpGrowthRate] = useState("");
const [flowRate, setFlowRate] = useState("");
function keyPress(e){
if(e.keyCode === 13 || e.key === 'Enter' ){
if(document.getElementById("searchInput")){
// console.log('value', e.target.value);
e.preventDefault();
setGrowthRateOfFCF(e.target.value)
setPerpGrowthRate(e.target.value)
setFlowRate(e.target.value)
}
}
}
return(
<div>
<h1> Flow Model</h1>
<form className='inputField'>
<input
type="number"
placeholder='growth Rate Input'
pattern="[0-9]*"
onKeyDown={keyPress}
/>
<input
type="number"
placeholder='perpGrowthRate'
pattern="[0-9]*"
onKeyDown={keyPress}
/>
<input
type="number"
placeholder='Flow Rate'
pattern="[0-9]*"
onKeyDown={keyPress}
/>
</form>
<table className="table mt-5">
<tbody>
<tr>
<th>Input</th>
<th>Growth</th>
<th>Growth Rate</th>
<th>Flow Rate</th>
</tr>
</tbody>
<tbody>
<FlowModel
input = {searchBarText}
growth = {growthRateInput/100}
growthRate = {perpGrowthRate}
rate = {flowRate}
/>
</tbody>
</table>
</div>
);
}
export default DCF;