2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-16 20:15:44 +00:00

use state to handle rerenders

This commit is contained in:
Matthias Mair
2024-05-05 23:44:24 +02:00
parent ecc3b25464
commit 6719eb810b

View File

@ -42,7 +42,7 @@ import {
} from '@tabler/icons-react'; } from '@tabler/icons-react';
import { Html5Qrcode } from 'html5-qrcode'; import { Html5Qrcode } from 'html5-qrcode';
import { CameraDevice } from 'html5-qrcode/camera/core'; import { CameraDevice } from 'html5-qrcode/camera/core';
import { useEffect, useState } from 'react'; import { ReactNode, useEffect, useState } from 'react';
import { api } from '../../App'; import { api } from '../../App';
import { DocInfo } from '../../components/items/DocInfo'; import { DocInfo } from '../../components/items/DocInfo';
@ -398,30 +398,35 @@ function HistoryTable({
setSelection((current) => setSelection((current) =>
current.length === data.length ? [] : data.map((item) => item.id) current.length === data.length ? [] : data.map((item) => item.id)
); );
const [rows, setRows] = useState<ReactNode>();
const rows = data.map((item) => { useEffect(() => {
return ( setRows(
<tr key={item.id}> data.map((item) => {
<td> return (
<Checkbox <tr key={item.id}>
checked={selection.includes(item.id)} <td>
onChange={() => toggleRow(item.id)} <Checkbox
transitionDuration={0} checked={selection.includes(item.id)}
/> onChange={() => toggleRow(item.id)}
</td> transitionDuration={0}
<td> />
{item.pk && item.model && item.instance ? ( </td>
<RenderInstance model={item.model} instance={item.instance} /> <td>
) : ( {item.pk && item.model && item.instance ? (
item.ref <RenderInstance model={item.model} instance={item.instance} />
)} ) : (
</td> item.ref
<td>{item.model}</td> )}
<td>{item.source}</td> </td>
<td>{item.timestamp?.toString()}</td> <td>{item.model}</td>
</tr> <td>{item.source}</td>
<td>{item.timestamp?.toString()}</td>
</tr>
);
})
); );
}); }, [data, selection]);
// rendering // rendering
if (data.length === 0) if (data.length === 0)