I have a component that simply renders a row of data and has a delete button for each row. Clicking delete should simply change the state using a filter to filter out the clicked row. Why do I get the error below.
I tried debugging use the console.log and I am indeed getting the correct row.id and rowId to filter on, but my rows state is not being reassigned.
interface TableSampleProps {
rows: any[];
}
interface TableSampleState {
rows: any[];
}
export class TableSample extends React.Component<TableSampleProps, TableSampleState> {
constructor(props: TableSampleProps) {
super(props);
this.state = {
rows: this.props.rows.concat(),
};
}
public render() {
return <MyTable rows={this.state.rows} onDeleteRow={this.deleteRow} />;
}
private deleteRow = (rowId: number) => {
// console.log(rowId);
// this.state.rows.filter((row) => console.log(row.id !== rowId));
this.setState = {
rows: this.state.rows.filter((row) => row.id !== rowId),
};
}
}
] ERROR in ./src/ts/components/table-sample-tool.tsx [0] (57,13): error TS2322: Type '{ rows: any[]; }' is not assignable to type '{ (f: (prevState: TableSample State, props: TableSampleProps) => Pick, ...'. [0] Object literal may only specify known properties, and 'rows' does not exist in type '{ (f: (prevS tate: TableSampleState, props: TableSampleProps) => Pick, ...'. [0] Child html-webpack-plugin for "index.html": [0] chunk {0} index.html 542 kB [entry] [0]
+ 4 hidden modules [0] webpack: Failed to compile.