import React from "react";
import { Switch } from "@mui/material";
import { useState ,useRef} from "react";
import { useEffect } from "react";
import axios from "axios";
function DailyStock() {
const [data, setData] = useState([]);
useEffect(() => {
getDailyData();
}, []);
const getDailyData =()=>{
axios.get("http://localhost:4000/api/stocks/view-stock").then((res) => {
const getData = res.data.data;
setData(getData);
});
}
return (
<div className="row">
<table
id="datatable-buttons"
className="table table-bordered dt-responsive nowrap w-100 "
>
<thead>
<tr>
<th>
<center>Product Name</center>
</th>
<th>
<center>Sold Quantity</center>
</th>
</tr>
</thead>
{data?.map((item) => {
return (
<tr>
<td>
<h5 className="ps-5">{item.pName}</h5>
</td>
<td>
<input
type="number"
className="form-control"
placeholder="XXX"
onChange={(e)=>{e.target.value==(item.pQty-item.saleStock) && <><p>Value is Matching</p></> }}
/>
</td>
</tr>
);
})}
</table>
</div>
);
}
export default DailyStock;
I fetched values from the database to dataTable. It works perfectly. Each row has an input box and its given value should be equal to the fetched value of DB. then printing as "value is matching". I tried it from the "onChange" event. it doesn't work. when I am using state. It applied to all rows. I just need to check row by row.