UNPKG

654 BTypeScriptView Raw
1import * as React from 'react';
2import type { SceneRendererProps } from './types';
3
4class SceneComponent<
5 T extends { component: React.ComponentType<any> }
6> extends React.PureComponent<T> {
7 render() {
8 const { component, ...rest } = this.props;
9 return React.createElement(component, rest);
10 }
11}
12
13export default function SceneMap<T extends any>(scenes: {
14 [key: string]: React.ComponentType<T>;
15}) {
16 return ({ route, jumpTo, position }: SceneRendererProps & { route: any }) => (
17 <SceneComponent
18 key={route.key}
19 component={scenes[route.key]}
20 route={route}
21 jumpTo={jumpTo}
22 position={position}
23 />
24 );
25}