├── .eslintrc.json ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── __tests__ └── 01_basic_spec.ts ├── dist ├── index.esm.js ├── index.esm.js.map ├── index.js ├── index.js.map ├── index.umd.js ├── index.umd.js.map └── src │ ├── FetchData.d.ts │ ├── RouteDataContext.d.ts │ ├── Routes.d.ts │ ├── index.d.ts │ └── types.d.ts ├── examples ├── 01_minimal │ ├── package.json │ ├── public │ │ └── index.html │ └── src │ │ └── index.js ├── 02_typescript │ ├── package.json │ ├── public │ │ └── index.html │ └── src │ │ ├── App.tsx │ │ ├── MyRoutes.tsx │ │ ├── Nav.tsx │ │ ├── index.tsx │ │ ├── pages │ │ ├── About.tsx │ │ ├── Index.tsx │ │ ├── User.data.ts │ │ └── User.tsx │ │ └── ssr.tsx ├── 03_nesting │ ├── package.json │ ├── public │ │ └── index.html │ └── src │ │ ├── App.tsx │ │ ├── MyRoutes.tsx │ │ ├── Nav.tsx │ │ ├── index.ts │ │ └── pages │ │ ├── FirstUser.data.ts │ │ ├── FirstUser.tsx │ │ ├── Index.tsx │ │ ├── Post.data.ts │ │ ├── Post.tsx │ │ ├── Posts.tsx │ │ ├── User.data.ts │ │ └── User.tsx └── server.ts ├── package.json ├── src ├── FetchData.ts ├── RouteDataContext.tsx ├── Routes.tsx ├── index.ts └── types.ts ├── tsconfig.json ├── webpack.config.js └── yarn.lock /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "@typescript-eslint/parser", 3 | "plugins": [ 4 | "@typescript-eslint", 5 | "react-hooks" 6 | ], 7 | "extends": [ 8 | "plugin:@typescript-eslint/recommended", 9 | "airbnb" 10 | ], 11 | "env": { 12 | "browser": true 13 | }, 14 | "settings": { 15 | "import/resolver": { 16 | "node": { 17 | "extensions": [".js", ".ts", ".tsx"] 18 | } 19 | } 20 | }, 21 | "rules": { 22 | "react-hooks/rules-of-hooks": "error", 23 | "react-hooks/exhaustive-deps": ["error", { "additionalHooks": "useIsomorphicLayoutEffect" }], 24 | "@typescript-eslint/explicit-function-return-type": "off", 25 | "react/jsx-filename-extension": ["error", { "extensions": [".js", ".tsx"] }], 26 | "react/prop-types": "off", 27 | "react/jsx-one-expression-per-line": "off", 28 | "react/jsx-props-no-spreading": "off", 29 | "import/extensions": ["error", "never"], 30 | "import/no-unresolved": ["error", { "ignore": ["react-suspense-router"] }], 31 | "no-underscore-dangle": ["error", { "allow": ["__ROUTE_DATA_MAP_CACHE__"] }], 32 | "camelcase": ["error", { "properties": "never", "ignoreDestructuring": false, "allow": ["first_name", "last_name"] }] 33 | }, 34 | "overrides": [{ 35 | "files": ["__tests__/**/*"], 36 | "env": { 37 | "jest": true 38 | }, 39 | "rules": { 40 | "import/no-extraneous-dependencies": ["error", { "devDependencies": true }] 41 | } 42 | }, { 43 | "files": ["examples/*"], 44 | "env": { 45 | "node": true 46 | }, 47 | "rules": { 48 | "import/no-extraneous-dependencies": ["error", { "devDependencies": true }], 49 | "no-console": "off" 50 | } 51 | }] 52 | } 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.swp 3 | node_modules 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 10 4 | - 12 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [Unreleased] 4 | 5 | ## [1.0.0-alpha.12] - 2020-06-18 6 | ### Changed 7 | - Fix react experimental version for now 8 | 9 | ## [1.0.0-alpha.11] - 2020-05-05 10 | ### Changed 11 | - Update based on react-router v6.0.0-alpha.4 12 | 13 | ## [1.0.0-alpha.10] - 2020-04-04 14 | ### Changed 15 | - Update based on react-router v6.0.0-alpha.3 16 | 17 | ## [1.0.0-alpha.9] - 2020-03-07 18 | ### Changed 19 | - Fix: Stable noop function in RouteDataContext 20 | 21 | ## [1.0.0-alpha.8] - 2020-03-07 22 | ### Changed 23 | - Update React Tracked v1.3.0 with a fix 24 | 25 | ## [1.0.0-alpha.7] - 2020-02-22 26 | ### Changed 27 | - Update based on react-router v6.0.0-alpha.2 28 | 29 | ## [1.0.0-alpha.6] - 2020-02-13 30 | ### Changed 31 | - Improve SSR example with Stream 32 | - Rename LazyFetcher to FetchDataLazy [BREAKING CHANGE] 33 | ### Added 34 | - New FetchData for async function 35 | 36 | ## [1.0.0-alpha.5] - 2020-02-11 37 | ### Changed 38 | - Eliminate "useLayoutEffect does nothing on the server" warning in SSR 39 | - Fix issues with hydration in SSR 40 | 41 | ## [1.0.0-alpha.4] - 2020-02-10 42 | ### Added 43 | - Experimental SSR support and an example 44 | 45 | ## [1.0.0-alpha.3] - 2020-02-08 46 | ### Changed 47 | - Better useListen hook from forked react-router 48 | - Fix showing canceled route data 49 | 50 | ## [1.0.0-alpha.1] - 2020-02-06 51 | ### Changed 52 | - Fix dependencies 53 | 54 | ## [1.0.0-alpha.0] - 2020-02-06 55 | ### Changed 56 | - Refactor and simplify with forked react-router 57 | 58 | ## [0.8.0] - 2020-02-06 59 | ### Added 60 | - Support HashRouter and MemoryRouter 61 | 62 | ## [0.7.0] - 2020-02-06 63 | ### Changed 64 | - Do not rely on routes object identity instead useRef 65 | 66 | ## [0.6.0] - 2020-02-05 67 | ### Changed 68 | - Improve the implementation of useRoutes without hacks 69 | 70 | ## [0.5.1] - 2020-02-04 71 | ### Changed 72 | - Fix routeData kept in different routes 73 | 74 | ## [0.5.0] - 2020-02-04 75 | ### Changed 76 | - Improve the implementation around initializedMap 77 | - Update react-tracked which improves Suspense support 78 | 79 | ## [0.4.0] - 2020-02-01 80 | ### Changed 81 | - Update react-tracked and make the implementation less tricky 82 | 83 | ## [0.3.1] - 2020-02-01 84 | ### Changed 85 | - Fix a bug that prevented Render-as-You-Fetch 86 | 87 | ## [0.3.0] - 2020-02-01 88 | ### Changed 89 | - Update react-router v6-alpha and completely rewritten 90 | 91 | ## [0.2.0] - 2020-01-30 92 | ### Added 93 | - Support Switch 94 | 95 | ## [0.1.0] - 2020-01-29 96 | ### Added 97 | - Initial release 98 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Daishi Kato 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-suspense-router 2 | 3 | [![Build Status](https://travis-ci.com/dai-shi/react-suspense-router.svg?branch=master)](https://travis-ci.com/dai-shi/react-suspense-router) 4 | [![npm version](https://badge.fury.io/js/react-suspense-router.svg)](https://badge.fury.io/js/react-suspense-router) 5 | [![bundle size](https://badgen.net/bundlephobia/minzip/react-suspense-router)](https://bundlephobia.com/result?p=react-suspense-router) 6 | 7 | React Router for React Suspense and Render-as-You-Fetch 8 | 9 | ## Introduction 10 | 11 | The new [Render-as-You-Fetch](https://reactjs.org/docs/concurrent-mode-suspense.html#approach-3-render-as-you-fetch-using-suspense) pattern is mind-blowing. 12 | 13 | This is an experimental library that combines react-router and some other libraries. 14 | You can get the benefit of Render-as-You-Fetch out of the box. 15 | 16 | ## Install 17 | 18 | ```bash 19 | yarn add react-suspense-router 20 | ``` 21 | 22 | ## Usage 23 | 24 | App.tsx 25 | 26 | ```tsx 27 | import React, { Suspense } from 'react'; 28 | 29 | import { BrowserRouter } from 'react-suspense-router'; 30 | 31 | import Nav from './Nav'; 32 | import MyRoutes from './MyRoutes'; 33 | 34 | const App: React.FC = () => ( 35 | 36 |