Closed FDiskas closed 4 years ago
Working typescript version without a plugin :frowning:
import * as React from 'react';
import { Route as ReactRoute, RouteProps } from 'react-router-dom';
export interface IRouteProps {
layout?: React.ComponentType<RouteProps> | React.ComponentType<any>;
component: React.ComponentType<RouteProps> | React.ComponentType<any>;
}
export interface IRouteState {
}
export class Route extends React.Component<IRouteProps & RouteProps, IRouteState> {
constructor(props: IRouteProps) {
super(props);
}
render() {
const { component, layout, ...rest } = this.props;
let routeComponent = (props: any) => React.createElement(component, props);
if (layout) {
routeComponent = props =>
React.createElement(layout, props, React.createElement(component, props));
}
return <ReactRoute {...rest} render={routeComponent} />;
}
}
In your error message, there is a reference to a DefaultLayout
. What is the declaration of it?
Besides that, your working typescript interface isn't compatible to your prop-types:
export interface IRouteProps {
layout?: React.ComponentType<RouteProps> | React.ComponentType<any>;
component: React.ComponentType<RouteProps> | React.ComponentType<any>;
}
Route.propTypes = {
layout: PropTypes.oneOfType([
PropTypes.func,
PropTypes.node,
]),
component: PropTypes.oneOfType([
PropTypes.func,
PropTypes.node,
]).isRequired,
};
DefaultLayout
its a component - not pure one. :ghost:
example could be found here https://github.com/nfq-eta/react-router4-with-layouts/blob/59e8917c0ba183e7ab4c5e7fd210ea74ccc03696/example/src/App.js
I think this
Route.propTypes = {
layout: PropTypes.oneOfType([
PropTypes.func,
PropTypes.node,
]),
component: PropTypes.oneOfType([
PropTypes.func,
PropTypes.node,
]).isRequired,
};
should better be:
Route.propTypes = {
layout: PropTypes.node,
component: PropTypes.node,
};
Failed prop type: Invalid prop component supplied to Route$$1, expected a ReactNode
You can test it here https://stackblitz.com/edit/react-kdwyaq?embed=1&file=lib/Router.js
I will do so when I find a bit of time.
:wedding:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
good one :D
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Currently this not works in typescripted project.
https://github.com/nfq-eta/react-router4-with-layouts/blob/59e8917c0ba183e7ab4c5e7fd210ea74ccc03696/src/index.jsx
https://unpkg.com/react-router4-with-layouts@1.0.2/dist/index.d.ts
Got the error: