React/Typescript Route component field type errorTypescript React: Access component property typesReact Component not showing on matched Route (react-router-dom)How to pass container components into react-router-dom Route?Converting React Component to Typescript?Stateless function with TypeScript error in React: TS2352 cannot be converted to type 'Promise<StatelessComponent<>>'Typescript React/Redux : Argument of type 'typeof MyClass' is not assignable to parameter of type 'ComponentType<…'How to properly type React connected components with TypeScriptreact routing using RouteComponentProps and custom propsPassing implementations of generic types to React component propsWarning: Failed prop type: Invalid prop `component` of type `object` supplied to `Route`, expected `function` Error using react-router-dom
Does a bard know when a character uses their Bardic Inspiration?
Export economy of Mars
How to handle many times series?
Is the first page of Novel really that important?
How to enable/disable Adobe host port in terminal?
How does Rust's 128-bit integer `i128` work on a 64-bit system?
Who's behind community AMIs on Amazon EC2?
Why are sugars in whole fruits not digested the same way sugars in juice are?
What is the most 'environmentally friendly' way to learn to fly?
How to understand "...to hide the evidence of mishandled magic, or else hidden by castle-proud house-elves" in this sentence
Why does BezierFunction not follow BezierCurve at npts>4?
Which honorific is correct, oshumi or goshumi?
Astable 555 circuit not oscillating
Phase portrait of a system of differential equations
Representation of the concatenation at the type level
How does shared_ptr<void> know which destructor to use?
What is a summary of basic Jewish metaphysics or theology?
Is Norway in the Single Market?
Subverting the essence of fictional and/or religious entities; is it acceptable?
Meaning of ギャップ in the following sentence
What is it exactly about flying a Flyboard across the English channel that made Zapata's thighs burn?
How was the cosmonaut of the Soviet moon mission supposed to get back in the return vehicle?
Accurately recalling the key - can everyone do it?
In MTG, was there ever a five-color deck that worked well?
React/Typescript Route component field type error
Typescript React: Access component property typesReact Component not showing on matched Route (react-router-dom)How to pass container components into react-router-dom Route?Converting React Component to Typescript?Stateless function with TypeScript error in React: TS2352 cannot be converted to type 'Promise<StatelessComponent<>>'Typescript React/Redux : Argument of type 'typeof MyClass' is not assignable to parameter of type 'ComponentType<…'How to properly type React connected components with TypeScriptreact routing using RouteComponentProps and custom propsPassing implementations of generic types to React component propsWarning: Failed prop type: Invalid prop `component` of type `object` supplied to `Route`, expected `function` Error using react-router-dom
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Trying to set up a browser router with some routes but typescript is throwing a type error on the components passed and won't compile.
I am using react typescript with the below code:
import BrowserRouter, Switch, Route from "react-router-dom";
export interface AppProps
const App: React.SFC<AppProps> = () =>
return (
<BrowserRouter>
<div className="App">
<Switch>
<Route exact path="/" component=Home />
<Route exact path="/feed" component=Feed />
<Route path="/project/:projectid" component=Project />
<Route path="/user/:userid" component=Profile />
</Switch>
</div>
</BrowserRouter>
);
;
export default App;
throws this error on each of the component fields of the
Type 'typeof import("/Users/colbygilbert/Documents/EOS/DevelopX/frontend/src/components/home/Home")' is not assignable to type 'ComponentClass<any, any> | FunctionComponent<any> | ComponentClass<RouteComponentProps<any, StaticContext, any>, any> | FunctionComponent<RouteComponentProps<any, StaticContext, any>> | undefined'.
Type 'typeof import("/Users/colbygilbert/Documents/EOS/DevelopX/frontend/src/components/home/Home")' is not assignable to type 'FunctionComponent<RouteComponentProps<any, StaticContext, any>>'.
Type 'typeof import("/Users/colbygilbert/Documents/EOS/DevelopX/frontend/src/components/home/Home")' provides no match for the signature '(props: RouteComponentProps<any, StaticContext, any> & children?: ReactNode; , context?: any): ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<...>)> | null'.ts(2322)
index.d.ts(87, 3): The expected type comes from property 'component' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<Route<RouteProps>> & Readonly< children?: ReactNode; > & Readonly<RouteProps>'
Here is an example of my Home component:
export interface HomeProps extends RouteComponentProps<>
auth: Auth;
const Home: React.SFC<HomeProps> = ( auth ) =>
if (auth.uid) return <Redirect to="/feed" />;
return (
<div>
<Nav size="bg" />
<div className="c_header__spacing">
<Vision />
<Demo />
<Featurette />
</div>
</div>
);
;
const mapStateToProps = (state: any) =>
return
auth: state.firebase.auth
;
;
export default connect(mapStateToProps)(Home);
Current dependencies:
"dependencies":
"@types/react-router": "^4.4.5",
"@types/react-router-dom": "^4.3.1",
"@types/react-router-redux": "^5.0.18",
"react-router": "^5.0.0",
"react-router-dom": "^5.0.0",
"react-router-redux": "^4.0.8",
"typescript": "3.3.3"
Any help or pointers would be greatly appreciated
reactjs typescript react-router-dom
add a comment |
Trying to set up a browser router with some routes but typescript is throwing a type error on the components passed and won't compile.
I am using react typescript with the below code:
import BrowserRouter, Switch, Route from "react-router-dom";
export interface AppProps
const App: React.SFC<AppProps> = () =>
return (
<BrowserRouter>
<div className="App">
<Switch>
<Route exact path="/" component=Home />
<Route exact path="/feed" component=Feed />
<Route path="/project/:projectid" component=Project />
<Route path="/user/:userid" component=Profile />
</Switch>
</div>
</BrowserRouter>
);
;
export default App;
throws this error on each of the component fields of the
Type 'typeof import("/Users/colbygilbert/Documents/EOS/DevelopX/frontend/src/components/home/Home")' is not assignable to type 'ComponentClass<any, any> | FunctionComponent<any> | ComponentClass<RouteComponentProps<any, StaticContext, any>, any> | FunctionComponent<RouteComponentProps<any, StaticContext, any>> | undefined'.
Type 'typeof import("/Users/colbygilbert/Documents/EOS/DevelopX/frontend/src/components/home/Home")' is not assignable to type 'FunctionComponent<RouteComponentProps<any, StaticContext, any>>'.
Type 'typeof import("/Users/colbygilbert/Documents/EOS/DevelopX/frontend/src/components/home/Home")' provides no match for the signature '(props: RouteComponentProps<any, StaticContext, any> & children?: ReactNode; , context?: any): ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<...>)> | null'.ts(2322)
index.d.ts(87, 3): The expected type comes from property 'component' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<Route<RouteProps>> & Readonly< children?: ReactNode; > & Readonly<RouteProps>'
Here is an example of my Home component:
export interface HomeProps extends RouteComponentProps<>
auth: Auth;
const Home: React.SFC<HomeProps> = ( auth ) =>
if (auth.uid) return <Redirect to="/feed" />;
return (
<div>
<Nav size="bg" />
<div className="c_header__spacing">
<Vision />
<Demo />
<Featurette />
</div>
</div>
);
;
const mapStateToProps = (state: any) =>
return
auth: state.firebase.auth
;
;
export default connect(mapStateToProps)(Home);
Current dependencies:
"dependencies":
"@types/react-router": "^4.4.5",
"@types/react-router-dom": "^4.3.1",
"@types/react-router-redux": "^5.0.18",
"react-router": "^5.0.0",
"react-router-dom": "^5.0.0",
"react-router-redux": "^4.0.8",
"typescript": "3.3.3"
Any help or pointers would be greatly appreciated
reactjs typescript react-router-dom
add a comment |
Trying to set up a browser router with some routes but typescript is throwing a type error on the components passed and won't compile.
I am using react typescript with the below code:
import BrowserRouter, Switch, Route from "react-router-dom";
export interface AppProps
const App: React.SFC<AppProps> = () =>
return (
<BrowserRouter>
<div className="App">
<Switch>
<Route exact path="/" component=Home />
<Route exact path="/feed" component=Feed />
<Route path="/project/:projectid" component=Project />
<Route path="/user/:userid" component=Profile />
</Switch>
</div>
</BrowserRouter>
);
;
export default App;
throws this error on each of the component fields of the
Type 'typeof import("/Users/colbygilbert/Documents/EOS/DevelopX/frontend/src/components/home/Home")' is not assignable to type 'ComponentClass<any, any> | FunctionComponent<any> | ComponentClass<RouteComponentProps<any, StaticContext, any>, any> | FunctionComponent<RouteComponentProps<any, StaticContext, any>> | undefined'.
Type 'typeof import("/Users/colbygilbert/Documents/EOS/DevelopX/frontend/src/components/home/Home")' is not assignable to type 'FunctionComponent<RouteComponentProps<any, StaticContext, any>>'.
Type 'typeof import("/Users/colbygilbert/Documents/EOS/DevelopX/frontend/src/components/home/Home")' provides no match for the signature '(props: RouteComponentProps<any, StaticContext, any> & children?: ReactNode; , context?: any): ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<...>)> | null'.ts(2322)
index.d.ts(87, 3): The expected type comes from property 'component' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<Route<RouteProps>> & Readonly< children?: ReactNode; > & Readonly<RouteProps>'
Here is an example of my Home component:
export interface HomeProps extends RouteComponentProps<>
auth: Auth;
const Home: React.SFC<HomeProps> = ( auth ) =>
if (auth.uid) return <Redirect to="/feed" />;
return (
<div>
<Nav size="bg" />
<div className="c_header__spacing">
<Vision />
<Demo />
<Featurette />
</div>
</div>
);
;
const mapStateToProps = (state: any) =>
return
auth: state.firebase.auth
;
;
export default connect(mapStateToProps)(Home);
Current dependencies:
"dependencies":
"@types/react-router": "^4.4.5",
"@types/react-router-dom": "^4.3.1",
"@types/react-router-redux": "^5.0.18",
"react-router": "^5.0.0",
"react-router-dom": "^5.0.0",
"react-router-redux": "^4.0.8",
"typescript": "3.3.3"
Any help or pointers would be greatly appreciated
reactjs typescript react-router-dom
Trying to set up a browser router with some routes but typescript is throwing a type error on the components passed and won't compile.
I am using react typescript with the below code:
import BrowserRouter, Switch, Route from "react-router-dom";
export interface AppProps
const App: React.SFC<AppProps> = () =>
return (
<BrowserRouter>
<div className="App">
<Switch>
<Route exact path="/" component=Home />
<Route exact path="/feed" component=Feed />
<Route path="/project/:projectid" component=Project />
<Route path="/user/:userid" component=Profile />
</Switch>
</div>
</BrowserRouter>
);
;
export default App;
throws this error on each of the component fields of the
Type 'typeof import("/Users/colbygilbert/Documents/EOS/DevelopX/frontend/src/components/home/Home")' is not assignable to type 'ComponentClass<any, any> | FunctionComponent<any> | ComponentClass<RouteComponentProps<any, StaticContext, any>, any> | FunctionComponent<RouteComponentProps<any, StaticContext, any>> | undefined'.
Type 'typeof import("/Users/colbygilbert/Documents/EOS/DevelopX/frontend/src/components/home/Home")' is not assignable to type 'FunctionComponent<RouteComponentProps<any, StaticContext, any>>'.
Type 'typeof import("/Users/colbygilbert/Documents/EOS/DevelopX/frontend/src/components/home/Home")' provides no match for the signature '(props: RouteComponentProps<any, StaticContext, any> & children?: ReactNode; , context?: any): ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<...>)> | null'.ts(2322)
index.d.ts(87, 3): The expected type comes from property 'component' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<Route<RouteProps>> & Readonly< children?: ReactNode; > & Readonly<RouteProps>'
Here is an example of my Home component:
export interface HomeProps extends RouteComponentProps<>
auth: Auth;
const Home: React.SFC<HomeProps> = ( auth ) =>
if (auth.uid) return <Redirect to="/feed" />;
return (
<div>
<Nav size="bg" />
<div className="c_header__spacing">
<Vision />
<Demo />
<Featurette />
</div>
</div>
);
;
const mapStateToProps = (state: any) =>
return
auth: state.firebase.auth
;
;
export default connect(mapStateToProps)(Home);
Current dependencies:
"dependencies":
"@types/react-router": "^4.4.5",
"@types/react-router-dom": "^4.3.1",
"@types/react-router-redux": "^5.0.18",
"react-router": "^5.0.0",
"react-router-dom": "^5.0.0",
"react-router-redux": "^4.0.8",
"typescript": "3.3.3"
Any help or pointers would be greatly appreciated
reactjs typescript react-router-dom
reactjs typescript react-router-dom
edited Mar 27 at 17:04
Colby Gilbert
asked Mar 27 at 1:01
Colby GilbertColby Gilbert
213 bronze badges
213 bronze badges
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55368307%2freact-typescript-route-component-field-type-error%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55368307%2freact-typescript-route-component-field-type-error%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown