minesweeper icon indicating copy to clipboard operation
minesweeper copied to clipboard

Update deps and fix types

Open nickovchinnikov opened this issue 2 years ago • 0 comments

Igal Kleiner comment:

In React 18 the FunctionComponent interface was changed and the implicit 'children' prop was omitted. You can find the reason here. Now you have to include the 'children' type by yourself. So here's the full solution. That will fix the "Property 'children' does not exist on type {}" error:

import { FC, PropsWithChildren } from 'react'
  
 // ...rest of the code
  
 interface HeaderProps {
   logo: string
 }
  
 interface LinkProps {
   href: string
   target?: '_blank' | '_self' | '_parent' | '_top'
   rel?: string
 }
  
 const Header: FC<PropsWithChildren<HeaderProps>> = ({ children, logo }) => (
   <header className='App-header'>
     <img src={logo} className='App-logo' alt='logo' />
     {children}
   </header>
 )
  
 const Link: FC<PropsWithChildren<LinkProps>> = ({ children, href, target = '_blank', rel = 'noopener noreferrer' }) => {
   return (
     <a className='App-link' href={href} target={target} rel={rel}>
       {children}
     </a>
   )
 }

Notice that 'PropsWithChildren' import. If, for example, you only want to use the 'children' prop, without passing any other prop, then you can use it without stating the props type for PropsWithChildren, ie:

const MyComponent: FC<PropsWithChildren> = ({ children }) => <div>{ children }</div>

Cheers!

nickovchinnikov avatar Aug 31 '22 09:08 nickovchinnikov