Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Type of React.cloneElement, React.Children.map

$
0
0
const element = React.Children.map(children, (child) => { -->     if (child.type !== CardFooter) return React.cloneElement(child);  });

child & child.type prompts TS error.

"Property 'type' does not exist on type 'string | number | boolean |{} | ReactElement<any,string | JSXElementConstructor> |ReactPortal'.

Property 'type' does not exist on type 'string'. ts(2339)"

Update:Use the isValidElement type guard to bypass this problem.

//Like thisconst element = React.Children.map(children, (child) => {    if (React.isValidElement(child)) {      if (child.type !== CardFooter) return React.cloneElement(child);    }  });

Viewing all articles
Browse latest Browse all 6287

Trending Articles