I am just trying to figure out how to use prevState
in the useState hook with React typescript. The button are mapped using the data from the objectData.
So far I have:
let data = dataFromFile;
const [chart, setChart] = React.useState<ChartInterface[]>(data);
in the component I am doing:
export interface ActiveObject {
id: number;
title: string;
cb: (idx: number) => void;
};
export interface ButtonGroupState {
activeObject: ActiveObject | null;
objects: ActiveObject[];
};
export interface ButtonGroupProps {
data: Array<ActiveObject>
}
const ObjectData: ActiveObject[] = [
{
id: 1,
title: "1 way day",
cb: () => { setChart(prevState => prevState.set(Data7Day)) }
},
];
But that does not really work, any idea's? I get Property 'set' does not exist on type 'ChartInterface[]'. I know thats to do with the interface, but is that the way to do use PrevState in useState and is it needed at all?