updated test and component prop of router

This commit is contained in:
Philipp Zins
2017-03-23 12:53:32 +01:00
parent fac784746d
commit 0d06ba4519
2 changed files with 15 additions and 9 deletions
+2 -3
View File
@@ -48,12 +48,11 @@ declare module 'react-router' {
history: H.History;
}
interface PartialRouteComponentProps<P> extends Partial<RouteComponentProps<P>> {
}
interface PartialRouteComponentProps<P> extends Partial<RouteComponentProps<P>> {}
interface RouteProps {
location?: H.Location;
component?: React.SFC<PartialRouteComponentProps<any> | void> | React.ComponentClass<PartialRouteComponentProps<any> | void>;
component?: React.SFC<RouteComponentProps<any> | void> | React.ComponentClass<RouteComponentProps<any> | void>;
render?: (props: RouteComponentProps<any>) => React.ReactNode;
children?: (props: RouteComponentProps<any>) => React.ReactNode | React.ReactNode;
path?: string;
+13 -6
View File
@@ -19,15 +19,22 @@ const find = (id: number) => PEEPS.find(p => p.id == id)
const RecursiveExample = () => (
<Router>
<Person match={{ params: { id: 0 }, url: '', path: '', isExact: true }} />
<Person match={{ params: { id: 0 }, url: '' }}/>
</Router>
)
interface PersonProps extends Partial<RouteComponentProps<{id: number}>> {
match: match<{id: number}>;
interface InitialPersonProps {
match: {
params: {
id: number;
};
url: string;
};
}
const Person: React.SFC<PersonProps> = ({ match }) => {
type PersonProps = RouteComponentProps<{ id: number }>;
const Person: React.SFC<InitialPersonProps | PersonProps> = ({ match }) => {
const person = find(match.params.id)
return (
@@ -42,9 +49,9 @@ const Person: React.SFC<PersonProps> = ({ match }) => {
</li>
))}
</ul>
<Route path={`${match.url}/:id`} component={Person}/>
<Route path={`${match.url}/:id`} component={Person as React.SFC<PersonProps>}/>
</div>
)
}
export default RecursiveExample
export default RecursiveExample