'How to pass the props to react functional component using react table and typescript?
i want to pass two arguments to react functional component using react table and typescript.
below is my code,
type NameCellValue = {
name: string;
type: string;
}
type NameCellProps = {
value: NameCellValue;
mode: Mode;
canOpen: boolean;
}
const NameCell: React.FC<NameCellProps> = ({
value: {name,type},
mode,
canOpen
}) => {
console.log(mode) //this is undefined
console.log(canOpen) //this is undefined
canOpen: boolean,
}
const buildColumns : (
mode: Mode,
canOpen?: boolean
) => Column<Data>[] = (mode, canOpen) => [
{
Header: 'Name',
id: 'name',
accessor: ({name, type}) => ({
name,
type,
}),
Cell: NameCell(mode, canOpen), //how do i pass mode and canOpen to NameCell
} as Column<Data, NameCellProps['value'] | NameCellProps['mode] | NameCellProps['canOpen']>,
];
const ParentComponent = () => {
const columns = buildColumns(mode, canOpen);
return (
//some jsx
);
}
the above doesnt work. it gives error "argument of type Mode is not assignable to parameter of type PropsWithChildren on line
Cell: NameCell(mode, canOpen)
also when i log the values of mode and canOpen within NameCell they are undefined.
could someone help me fix this. thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
