I am getting this error while trying to map an array with the object.
Type 'unknown' is not assignable to type 'ReactNode'.
Type 'unknown' is not assignable to type 'ReactPortal'.ts(2322)
index.d.ts(1353, 9): The expected type comes from property 'children' which is declared here on type 'DetailedHTMLProps<HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>'
Here is my code.
const data = [
{
label: "CLIENT ID",
value: "clientId",
},
{
label: "BILLING CUSTOMER ID",
value: "billingCustomerId",
},
{
label: "EMAIL",
value: "email",
},
{
label: "PHONE NUMBER",
value: "phoneNumber",
},
{
label: "BUSINESS NAME",
value: "businessName",
},
{
label: "BILLING ADDRESS",
value: "billingAddress",
},
{
label: "TAX DETAILS",
value: "taxDetails",
},
{
label: "LOCATION",
value: "location",
},
{
label: "LANGUAGE",
value: "language",
},
];
const ProfileDetail = (props: any) => {
const dispatch = useDispatch();
useEffect(() => {
if (clientId !== null && userMasterId !== null && accessToken !== null) {
clientDetail(accessToken, clientId);
}
}, [clientId, userMasterId, accessToken]);
const profileState: any = useSelector((state: any) => state.profileBilling);
const clientDetail = async (aToken: string, cId: string) => {
await dispatch(getClientDetailThunk(aToken, cId));
};
return (
<div>
{data.map((item: any, i: number) => {
return (
<Box marginY={2} key={item.label}>
<Typography className={classes.menuTitle}>{item.label}</Typography>
<p className={classes.menuSubtitle}>
{item.value === Object.keys(profileState?.cDetail)[i]. // I tried to map the array value like this so that i don't have to repeat this block of code.
? Object.values(profileState?.cDetail)[i]
: null}
</p>
</Box>
);
})}
</div>
);
};
export default ProfileDetail;
I am not sure if i am doing it write or wrong. But the code is working on UI but it is showing the typescript error which i am not sure how to resolve.
This how profileState.cDetail looks like.
{
billingAddress: "Street2",
billingCustomerId: "cus_Kf4ylZZmyALR6f",
businessName: "xxxxxxx",
clientId: "67f3b1f6",
email: "[email protected]",
language: "English",
location: "xxxx",
phoneNumber: "1234123412",
taxDetails: "123",
}