Reputation: 395
I'm trying to add or remove data from Zusand store based on row selection in the shadcn (tanstack) table.
import { useStore } from '@/lib/store'
const onStatusChange = async (value: string | boolean, row: any) => {
const { items, removeItem, updateQuantity, clearCart } = useStore();
const addItem = useStore((state: any) => state.addItem);
if (value) {
removeItem(row?.original?.id);
} else {
addItem(row.original);
}
}
export const Columns: ColumnDef<Module>[] = [
{
id: "select",
header: ({ table }) => (
<Checkbox
checked={table.getIsAllPageRowsSelected()}
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
aria-label="Select all"
/>
),
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(value) => {
onStatusChange(value, row.original);
row.toggleSelected(!!value)
}}
aria-label="Select row"
/>
),
enableSorting: false,
enableHiding: false,
},
}
I am getting following error
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
at following line
const { items, removeItem, updateQuantity, clearCart } = useCartStore();
Need help in understanding what this error means and how to resolve it.
Upvotes: 1
Views: 74