T
TanStack3y ago
ratty-blush

onChange of value in dropdown in cell, rerenders the complete table.

What I am doing 1. Loading dropdown in cell 2.onChange of value in dropdown I am setting one state in zustand store
// all columns
const columns = useMemo(
() => [
.
.
{
Header: "Warehouse",
accessor: "", // accessor is the "key" in the data
Cell: ({ value, row }) => {
return (
<>
<Select
placeholder="Select option"
w="10vw"
value={selectedWarehouse.name}
onChange={(e) => {
setSelectedWarehouse(e.target.value, row.original);
}}
>
{row.original.pincode_serviceable_by.map((warehouse) => (
<React.Fragment key={warehouse.warehouseInfo.alias_name}>
<option value={warehouse.warehouseInfo.alias_name}>
{warehouse.warehouseInfo.alias_name}
</option>
</React.Fragment>
))}
</Select>
</>
);
},
},
.
.
.
],
[selectedStore]
// all columns
const columns = useMemo(
() => [
.
.
{
Header: "Warehouse",
accessor: "", // accessor is the "key" in the data
Cell: ({ value, row }) => {
return (
<>
<Select
placeholder="Select option"
w="10vw"
value={selectedWarehouse.name}
onChange={(e) => {
setSelectedWarehouse(e.target.value, row.original);
}}
>
{row.original.pincode_serviceable_by.map((warehouse) => (
<React.Fragment key={warehouse.warehouseInfo.alias_name}>
<option value={warehouse.warehouseInfo.alias_name}>
{warehouse.warehouseInfo.alias_name}
</option>
</React.Fragment>
))}
</Select>
</>
);
},
},
.
.
.
],
[selectedStore]
setSelectedWarehouse: (warehouse, data) => {
//filtering warehouse
let filteredWarehouse = data.pincode_serviceable_by.filter(
(service) => service.warehouseInfo.alias_name === warehouse
)[0];

// getting courier for selected ware house
let availableCouriersData = filteredWarehouse.serviceAvailblity.filter(
(courier) => courier.code === 200
);

// if I skip this setting state dropdown will work as expected
set({
availableCouriers: availableCouriersData,
});
}
setSelectedWarehouse: (warehouse, data) => {
//filtering warehouse
let filteredWarehouse = data.pincode_serviceable_by.filter(
(service) => service.warehouseInfo.alias_name === warehouse
)[0];

// getting courier for selected ware house
let availableCouriersData = filteredWarehouse.serviceAvailblity.filter(
(courier) => courier.code === 200
);

// if I skip this setting state dropdown will work as expected
set({
availableCouriers: availableCouriersData,
});
}
const [tableData, setTableData] = useState([]);
const { isLoading, data, error } =useGetOrderFromDbById(selectedStore);
useEffect(() => {
if (data) {
setTableData(data);
}
}, [data]);
//table
<OrdersTable columns={columns} data={tableData} />
const [tableData, setTableData] = useState([]);
const { isLoading, data, error } =useGetOrderFromDbById(selectedStore);
useEffect(() => {
if (data) {
setTableData(data);
}
}, [data]);
//table
<OrdersTable columns={columns} data={tableData} />
https://www.loom.com/share/1837fdfe88f743428b709b1b769e7ffe
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?