I'm trying to build a bootstrap v3, ReactJS component using TypeScript.
The props are as following:
export interface ICheckboxProps {
checked?: boolean;
text: string | JSX.Element | (string | JSX.Element)[];
onChange?: (checked: boolean) => void;
}
As it can be seen, text can be a string, an JSX.Element or a listing of both.
This is the render method:
render(): JSX.Element {
const { text, checked = false } = this.props;
if (text instanceof Array) {
// what should I do with?
}
return (
<div className="checkbox">
<label>
<input type="checkbox" defaultChecked={checked} />{text}
</label>
</div>
);
}
In another component I use this one <Checkbox text={["I accept the ", <Oem.ExternalLink href={"https://some.link.here"} linkText={"terms & conditions"} />]} />
However, I get the following error/warning:
Each child in an array or iterator should have a unique "key" prop. Check the render method of
Checkbox
I know that it is related to the text property but I have no idea how I should add a key (even if I know that text is an array).