Download react-use/src/factory/createRouter.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 825 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/factory/createRouter.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/factory/createRouter.ts
-
curl -L -o createRouter.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/factory/createRouter.ts
825 Bytes
| import 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; | |