Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const handleDelete = async (itemId, idx) => {
- console.log(`asdsad`, itemId, idx);
- const category = buttons.txt[buttons.is];
- const updatedStates = [...results[category]];
- const index = idx; // Use the provided index instead of findIndex
- if (index !== -1) {
- updatedStates.splice(index, 1);
- }
- setResults((prevResults) => ({
- ...prevResults,
- [category]: updatedStates,
- }));
- const response = await fetch(`http://192.168.0.102:8000/delete/${buttons.is}/${itemId}`)
- .then((res) => res.json())
- .catch((err) => console.error(`errir`, err));
- console.log(`debug1`);
- console.log(`[Response spravka delete]`, response);
- };
- <tbody>
- {results[buttons.txt[buttons.is]] &&
- results[buttons.txt[buttons.is]].map((result, idx) => (
- <tr key={result._id}>
- {console.log(`id`, result)}
- <td>
- <div className='flex items-center space-x-3'>№{idx}</div>
- </td>
- {Object.keys(result).map((e, indx) => {
- if (e !== '_id' && e !== '__v') {
- return (
- <td key={indx}>
- <div className='flex items-center space-x-3'>{result[e]}</div>
- </td>
- );
- }
- return null;
- })}
- <th>
- <button className="btn btn-ghost btn-xs">edit</button>
- <button className='btn btn-ghost btn-xs' onClick={() => handleDelete(result._id, idx)}>
- delete
- </button>
- </th>
- </tr>
- ))}
- </tbody>
Advertisement
Add Comment
Please, Sign In to add comment