Mixing Read only and Normal Props
Unanswered
WhyFencePost posted this in #help-forum
I have a deceleration of an object which uses children as a
ReadOnly
item, but I need to add a boolean that is not read only. How do I do this?function VerticalCardWrapper({
children,
title,
description,
noBack,
noForward,
}: Readonly<{
children?: React.ReactNode,
title : string,
description : string,
noBack? : boolean,
noForward? : boolean,
}>) {
3 Replies
@WhyFencePost I have a deceleration of an object which uses children as a `ReadOnly` item, but I need to add a boolean that is not read only. How do I do this?
tsx
function VerticalCardWrapper({
children,
title,
description,
noBack,
noForward,
}: Readonly<{
children?: React.ReactNode,
title : string,
description : string,
noBack? : boolean,
noForward? : boolean,
}>) {
({...}:ReadOnly<{}> & {nonReadOnly:boolean})
Props should NOT be mutated, which means they're supposed to be Readonly anyway. But if you want to...
Btw this only seems to work if props aren't destructured..
type Props = Readonly<{
children?: React.ReactNode;
// choose which ones go here
}> & {
// choose which ones go here
noBack?: boolean;
noForward?: boolean;
title: string;
description: string;
};
function VerticalCardWrapper(props: Props) {
Btw this only seems to work if props aren't destructured..
@Yi Lon Ma ts
({...}:ReadOnly<{}> & {nonReadOnly:boolean})
thank you this worked