Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React TypeScript: (props: OwnProps) => Element' is not assignable to type 'FunctionComponent<{}>

As a JSX element, all is good...

interface OwnProps {
  children: JSX.Element;
  location: Location;
}

export function Layout(props: OwnProps): JSX.Element {

When I change it to a functional component I get an error on Layout

interface OwnProps {
  children: JSX.Element;
  location: Location;
}

const Layout: React.FC = (props: OwnProps) => {

The Error is

Type '(props: OwnProps) => Element' is not assignable to type 'FunctionComponent<{}>'.
  Types of parameters 'props' and 'props' are incompatible.
    Property 'location' is missing in type '{ children?: ReactNode; }' but required in type 'OwnProps'.ts(2322)
layout.tsx(18, 3): 'location' is declared here.
like image 676
Bill Avatar asked Aug 30 '26 20:08

Bill


1 Answers

React.FC is actually a generic type. You need to specify your prop type

const Layout: React.FC<OwnProps> = (props: OwnProps) => {}
like image 102
Hung Tran Avatar answered Sep 01 '26 09:09

Hung Tran



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!