Hello fellow coding friends,
I have a small problem. First of all I am very new to REACT and Typescript otherwise I think it would be no problem to solve this myself. But i need the following code to be implemented as a class (as I otherwise would need to duplicate this code):
const CustomFilterComponent = (props): ReactElement => {
const [selectedVal, setSelectedVal] = useState(0);
function handleChange(e): void {
const val = e.target.value;
setSelectedVal(val);
props.onFilterChanged(props.columnDef.tableData.id, val);
}
return (
<th>
<Select value={selectedVal} onChange={handleChange}>
<MenuItem value={"0"} disabled>
Filter
</MenuItem>
{phpVersions.map((phpVersion): ReactElement => {
return (
<MenuItem value={phpVersion}>{phpVersion}</MenuItem>
)
})}
</Select>
</th>
);
};
I need this to be a class as I am making a filter for php versions in my example. But I also need this for symfony as a reference. This means I would need to change the return property. At the moment i call my method like this:
const newColumns = [...this.state.columns];
newColumns[3].filterComponent = CustomFilterComponent;
this.setState({columns: newColumns});
I would very much appreciate your help.