Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSX.Element' is not assignable to type 'FunctionComponent<{}>'

I am starting with React and Typescript and my code editor is claiming about my Button component (error bellow), but to eslint seems to be fine.

import React from 'react'

interface Props {
  children: React.ReactChild | React.ReactChildren
}

const Button: React.FunctionComponent = ({ children }: Props) => {
  return <button>{children}</button>
}

export default Button

The error:

Type '({ children }: Props) => JSX.Element' is not assignable to type 'FunctionComponent<{}>'.
  Types of parameters '__0' and 'props' are incompatible.
    Type '{ children?: ReactNode; }' is not assignable to type 'Props'.
      Types of property 'children' are incompatible.
        Type 'ReactNode' is not assignable to type 'string | number | ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<...>)> | ReactChildren'.
          Type 'undefined' is not assignable to type 'string | number | ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => 

What is wrong on my code?

like image 349
Rodrigo Avatar asked Oct 16 '25 13:10

Rodrigo


1 Answers

Found the problem, shoud be:

const Button: React.FunctionComponent<Props> = ({ children }: Props) => (
  <button>{children}</button>
)

I was forgetting the Props on React.FunctionComponent

like image 128
Rodrigo Avatar answered Oct 18 '25 06:10

Rodrigo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!