I am trying to refactor some react-typescript code and I want to make one general component, and call it with different parameters several times, instead of having several components that work in the same way.
So I am using redux as well, and the way it works is that in each component I call the redux state, and now I want to do it differently.
I have made a component that is called DrawerItems and in there I have defined :
type DrawerItemProps = {
open: boolean,
tabs: boolean[],
}
const DrawerItems = ({ open, tabs }: DrawerItemProps) => {
.
.
.
}
in my parent component I have
const jaTabs = useSelector((state: TabState) => state.JA.tabs);
const checkedOpen = useSelector((state: TabState) => state.JA.open);
and then I want to pass the to my child component like:
<DrawerItems open={checkedOpen } tabs={jaTabs } />
this generates the error:
Type '{ trunk: boolean; hip: boolean; knee: boolean; ankle: boolean; }' is missing the following properties from type 'boolean[]': length, pop, push, concat, and 29 more.
My state looks like this:
export interface TabState {
ja: {
open : boolean;
tabs : {
trunk: boolean;
hip: boolean;
knee: boolean;
ankle: boolean;
}
}
//=================
fp: {
open : boolean;
tabs : {
clearanceSwing: boolean;
footOrientation: boolean;
}
}
//=================
gt: {
open : boolean;
tabs : {
gaitWidth: boolean;
centerOfMass: boolean;
eCenterOfMass: boolean;
}
}
//=================
tm: {
open : boolean;
tabs : {
gaitSpeed: boolean;
stancePhaseDuration: boolean;
swingPhaseDuration: boolean;
}
}
//=================
distance: {
open : boolean;
tabs : {
stepLength: boolean;
strideLength: boolean;
distanceWalked: boolean;
}
}
}
how can I correctly pass the boolean array down to my child component?
I want to be able to pass the tabs everytime to my DrawerItem how can I do that?
tabstype as an array of booleans but in your TabState interface, you have an object that contains boolean values. I believe this mismatch is what's raising an error.