mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
37 lines
828 B
TypeScript
37 lines
828 B
TypeScript
import * as React from 'react';
|
|
|
|
export interface RouterProviderProps {
|
|
route: string;
|
|
fullRoute?: string;
|
|
parent?: any;
|
|
}
|
|
|
|
const createRouter = () => {
|
|
const context = React.createContext<RouterProviderProps>({
|
|
route: '',
|
|
});
|
|
|
|
// not sure if this supposed to be unused, ignoring ts error for now
|
|
// @ts-ignore
|
|
const Router: React.SFC<RouterProviderProps> = props => {
|
|
const { route, fullRoute, parent, children } = props;
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
if (typeof route !== 'string') {
|
|
throw new TypeError('Router route must be a string.');
|
|
}
|
|
}
|
|
|
|
return React.createElement(context.Provider as any, {
|
|
value: {
|
|
fullRoute: fullRoute || route,
|
|
route,
|
|
parent,
|
|
},
|
|
children,
|
|
});
|
|
};
|
|
};
|
|
|
|
export default createRouter;
|