2

When using:

<Route path={rootPath} exact render={props => <LoginLayout {...props} />} />

in typescript LoginLayout when prompts an error:

Type '{ history: History<PoorMansUnknown>; location: Location<PoorMansUnknown>; match: match<any>; staticContext?: StaticContext | undefined; }' has no properties in common with type 'IntrinsicAttributes & { children?: ReactNode; }'.ts(2559)

I tried to add:

const LoginLayout:FunctionComponent = (props: any) => { ... };

<Route path={rootPath} exact render={(props: any) => <LoginLayout {...props} />} />

But it doesn't work. I also tried:

const LoginLayout:FunctionComponent = (props: RouteComponentProps) => { ... };

<Route path={rootPath} exact render={(props: RouteComponentProps) => <LoginLayout {...props} />} />

And it doesn't work...

2 Answers 2

4

It complains because you're passing props (RouteComponentProps) to component which doesn't expect to get them. To fix:

const LoginLayout: FunctionComponent<RouteComponentProps> = () => {...};

Or even shorter:

const LoginLayout: FC<RouteComponentProps> = () => {...};

Playground

Sign up to request clarification or add additional context in comments.

Comments

1

Extend 'RouterComponentProps' from 'react-router- and then use it in your functional component

import React, { FunctionComponent } from "react";
import { RouteComponentProps } from "react-router";

type Props = { component: FunctionComponent } & RouteComponentProps;

const LoginLayout: FunctionComponent<Props> = () => {...};

export default LoginLayout;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.