Skip to content
Merged

v3 #1360

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
165 commits
Select commit Hold shift + click to select a range
9876f23
feat: initial v3 changes (#1079)
boschni Sep 26, 2020
25e323a
force website deploy
tannerlinsley Sep 26, 2020
ee2d600
docs: v3 updates
tannerlinsley Sep 26, 2020
96ac8b2
docs: More documentation improvements
tannerlinsley Sep 26, 2020
6ecef72
docs: update query filters page
tannerlinsley Sep 26, 2020
31901c9
docs: update query keys
tannerlinsley Sep 26, 2020
35eb838
docs: more updates
tannerlinsley Sep 26, 2020
5996af8
docs: updates
boschni Sep 27, 2020
e049941
feat: support multiple subscribers in observers
boschni Sep 27, 2020
88b288b
docs: useMutation updates
boschni Sep 27, 2020
e160d46
fix: mutate argument types and state update order
boschni Sep 27, 2020
b13a4c8
fix: remove cache argument in cache callback
boschni Sep 27, 2020
a817b5e
fix: move optimistic fetching state into query observer
boschni Sep 27, 2020
469cf8d
fix: make sure default options can be overridden
boschni Sep 28, 2020
84f93fc
fix: type improvements
boschni Sep 28, 2020
9fbc739
feat: memoize select function result
boschni Sep 28, 2020
c8f6634
fix: only suspend when mounting
boschni Sep 28, 2020
027791e
docs: refactor to top level pages and multiple api reference pages pe…
tannerlinsley Sep 28, 2020
1e14964
test: add remove query test
boschni Sep 28, 2020
4c64cb9
feat: add filters client isFetching and useIsFetching hook
boschni Sep 28, 2020
0feae60
docs: temp move docs back to docs directory
tannerlinsley Sep 28, 2020
b2d479f
Merge branch '3.0.x' of https://github.com/tannerlinsley/react-query …
tannerlinsley Sep 28, 2020
38c35e2
docs: solve conflicts
tannerlinsley Sep 28, 2020
58e2d15
docs: fix queryClient reference
tannerlinsley Sep 28, 2020
4c87a15
docs: reorg directory structure
tannerlinsley Sep 28, 2020
1cdb6e7
docs: fix queryClient reference
tannerlinsley Sep 28, 2020
b347fec
docs: fix links
tannerlinsley Sep 28, 2020
ae5c25c
docs: better phrasing
tannerlinsley Sep 28, 2020
d827c45
docs: force docs build
tannerlinsley Sep 29, 2020
7ce62f8
docs: update examples
boschni Sep 29, 2020
f9aac2a
fix: use updatedAt to check for existing data
boschni Sep 29, 2020
f9dc85a
feat: add structural sharing to select result
boschni Sep 29, 2020
fe181f9
refactor: update hashing terminology
boschni Oct 1, 2020
0f7c2af
test: add ability to wrap react query updates with React act
boschni Oct 1, 2020
1262259
refactor: replace console with logger implementation
boschni Oct 1, 2020
494f648
docs: add migration page to navigation
boschni Oct 2, 2020
a071ef5
docs: update installation docs
tannerlinsley Oct 2, 2020
8645539
refactor: reduce file size
boschni Oct 3, 2020
495bed5
Merge branch 'master' into next
boschni Oct 4, 2020
8c40ea5
docs: update examples
boschni Oct 4, 2020
4d85cf9
fix: always compare query keys as arrays
boschni Oct 4, 2020
02b2493
refactor: mark observers as private
boschni Oct 4, 2020
9c47a0d
test: update timings in hydration cache time test
boschni Oct 4, 2020
fee1376
docs: Update queries.md (#1134)
cseas Oct 4, 2020
8da45d1
feat: split mutate into mutate and mutateAsync (#1130)
boschni Oct 4, 2020
b6b1dc6
feat: add bi-directional infinite query support (#1135)
boschni Oct 5, 2020
7d65bef
refactor: reduce file size
boschni Oct 5, 2020
765740d
feat: revert to previous state on cancellation
boschni Oct 5, 2020
0f7fdd7
fix: wait for all queries to cancel
boschni Oct 5, 2020
58b6558
docs: update cancellation docs
boschni Oct 5, 2020
085b2f7
build: force
tannerlinsley Oct 5, 2020
ad597e6
build: add beta build
tannerlinsley Oct 5, 2020
af4deee
build: add beta build
tannerlinsley Oct 5, 2020
2207474
docs: update comparison
tannerlinsley Oct 5, 2020
c6e6cdf
fix: support infinite cache time when hydrating
boschni Oct 6, 2020
a057829
refactor: explicitly mark package side effects
boschni Oct 6, 2020
15100e6
docs: update comparison
tannerlinsley Oct 6, 2020
1c4e9bb
Merge branch 'beta' of https://github.com/tannerlinsley/react-query i…
tannerlinsley Oct 6, 2020
4e2827c
docs: update comparison
tannerlinsley Oct 6, 2020
1de4ca9
fix: remove excess exports
boschni Oct 6, 2020
dcb3e7f
feat: add support for default options when hydrating
boschni Oct 7, 2020
de0492f
docs: fix links
boschni Oct 7, 2020
1f5b13e
feat: add options to setQueryData
boschni Oct 7, 2020
07d4796
fix: align notify terminology
boschni Oct 7, 2020
b8bcea9
feat: Major semver bump
tannerlinsley Oct 8, 2020
0ba75af
Merge remote-tracking branch 'origin/master' into beta
boschni Oct 9, 2020
2c6bace
fix: always try to fetch if enabled
boschni Oct 9, 2020
2b4ed22
feat: bump version
boschni Oct 9, 2020
ffff53f
fix: refetch should create new query when removed
boschni Oct 9, 2020
5aeec5b
chore: do not publish beta until we figure this out
tannerlinsley Oct 9, 2020
aeb92c4
make beta prerelease
tannerlinsley Oct 9, 2020
68a96db
dry run releases
tannerlinsley Oct 9, 2020
f596b73
fix: test dry run semantic release
tannerlinsley Oct 9, 2020
00a3fdf
release beta releases for realzies
tannerlinsley Oct 9, 2020
fab235c
test: add eslint rule
boschni Oct 11, 2020
f4b2bdc
Merge remote-tracking branch 'origin/master' into beta
boschni Oct 11, 2020
7abc26a
docs(useQuery): change manual to enabled (#1167)
jpangelle Oct 14, 2020
eb5078b
feat: move mutations into the core (#1162)
boschni Oct 16, 2020
42b33f1
feat: tree shake infinite query and support manual updates
boschni Oct 18, 2020
6400708
docs: update comparison
boschni Oct 18, 2020
10db6b3
refactor: remove observer factory
boschni Oct 18, 2020
6ed3421
refactor: add subscribable
boschni Oct 20, 2020
f9fc4ba
refactor: move hasListeners
boschni Oct 20, 2020
e42ed2b
refactor: optimize bundle
boschni Oct 20, 2020
bc37266
fix: add status bools to use mutation result
boschni Oct 21, 2020
b65c0a0
Merge remote-tracking branch 'origin/master' into beta
boschni Oct 22, 2020
5bee9b6
feat: api update
boschni Oct 22, 2020
a92d643
fix: add defaults to UseMutationOptions type
boschni Oct 22, 2020
75199ba
docs: add pages
boschni Oct 22, 2020
f0ac65c
fix: cleanup
boschni Oct 22, 2020
a126f30
refactor: use queryCache property directly
boschni Oct 22, 2020
426b505
docs: Add placeholder data guide
tannerlinsley Oct 22, 2020
6e8ed8d
docs: fix typo
tannerlinsley Oct 22, 2020
6e7de8f
fix: keep previous query status when fetching
boschni Oct 23, 2020
90d8e81
fix: stop retry when observers unmount
boschni Oct 23, 2020
f559d25
feat: add additional notify flags
boschni Oct 23, 2020
94c3e9e
fix: only keep notify on stale option
boschni Oct 23, 2020
cdb2972
refactor: only batch react callbacks
boschni Oct 24, 2020
167f196
test: update timings
boschni Oct 24, 2020
9a6e59e
refactor: also batch in suspense
boschni Oct 24, 2020
3545362
feat: add hydration support for mutations
boschni Oct 24, 2020
8b57710
fix: remove query immediately if cacheTime is 0
boschni Oct 24, 2020
bc4a001
fix: prevent infinite fetch loop
boschni Oct 24, 2020
4e762db
refactor: move refetch logic into observer
boschni Oct 26, 2020
65f9f12
fix: match query key correctly when setting defaults
boschni Oct 26, 2020
83a1ba6
test: add query defaults test
boschni Oct 26, 2020
81299ff
fix: re-add useMutation callback composition
boschni Oct 27, 2020
2d98bf2
feat: use set defaults also for observers
boschni Oct 30, 2020
5c6cce6
test: add enabled assertion
boschni Oct 30, 2020
6b3840b
feat: add ability to manually control the online and focus state
boschni Nov 1, 2020
3e0a874
docs: update onlineManager documentation
boschni Nov 2, 2020
7d85074
feat: add discriminated unions for query results (#1247)
boschni Nov 2, 2020
4931201
fix: only set state in listeners when provided
boschni Nov 3, 2020
fca1f5a
docs: add testing page
tannerlinsley Nov 3, 2020
9cef1ea
feat: add query function context (#1261)
boschni Nov 6, 2020
c47f415
feat: add errorUpdatedAt property
boschni Nov 6, 2020
360d38c
fix: only trigger suspense when loading for the first time
boschni Nov 7, 2020
f0d32ca
fix: make sure suspense is always triggered when loading a query
boschni Nov 9, 2020
06833ba
fix: add ability to type the query key in the query function context
boschni Nov 9, 2020
617c758
refactor: make isDataEqual type more specific
boschni Nov 12, 2020
2a9b8d5
docs: update react native focus code
boschni Nov 12, 2020
7432998
fix: make sure to remove the correct query from cache
boschni Nov 12, 2020
74d1106
test: remove only
boschni Nov 12, 2020
d01f52d
Merge remote-tracking branch 'origin/master' into beta
boschni Nov 15, 2020
99951a0
feat: add granular component re-render control
boschni Nov 19, 2020
46a7346
fix: make sure component re-render when they should
boschni Nov 20, 2020
70647f9
Merge remote-tracking branch 'origin/master' into beta
boschni Nov 20, 2020
163339f
feat: throw error when QueryClientProvider has not been used to set a…
JakeGinnivan Nov 22, 2020
09a6545
test: add invalidateQueries test
boschni Nov 22, 2020
9d66f43
fix: prevent state update after mutation unmounted
boschni Nov 22, 2020
05b2c2d
fix: add defaults to setQueryData
boschni Dec 2, 2020
f07ece1
fix: cancellations for useInfiniteQuery (#1359)
Tommos0 Dec 6, 2020
ba9e936
chore: update TypeScript version (#1314)
Lisenish Dec 7, 2020
4d01e1f
Merge branch 'master' into beta
tannerlinsley Dec 7, 2020
16100de
Merge branch 'master' into beta
tannerlinsley Dec 8, 2020
2aff467
fix(hydration): set fetchMeta to null by default to make it serializa…
tatchi Dec 8, 2020
d2ba877
Merge branch 'beta' of https://github.com/tannerlinsley/react-query i…
tannerlinsley Dec 8, 2020
0ad9168
fix(hasPageParam): look for (undefined | null | false) values
tannerlinsley Dec 9, 2020
d773e97
chore: fix linting
tannerlinsley Dec 9, 2020
e8a22e9
fix: cross-bundle/version query client context
tannerlinsley Dec 9, 2020
506e4ca
docs: Update Examples
tannerlinsley Dec 9, 2020
963c3f6
docs: update example deps
tannerlinsley Dec 9, 2020
9ef8804
docs: keepPreviousData not set in paginated queries docs (#1376)
jrmyio Dec 9, 2020
db30199
docs: typo infinite instead of ininite (#1379)
rubenmoya Dec 9, 2020
26db5a4
feat: devtools are now native to the core repo/npm-package
tannerlinsley Dec 10, 2020
ced9a9b
Merge branch 'beta' of https://github.com/tannerlinsley/react-query i…
tannerlinsley Dec 10, 2020
3adc288
feat(persist-localstorage-experimental): temporarily persist cache to…
tannerlinsley Dec 10, 2020
05b398f
tests: fix linting
tannerlinsley Dec 10, 2020
0ba1899
chore: attempt codesandbox import fix
tannerlinsley Dec 10, 2020
50ac608
chore: revert codesandbox fix
tannerlinsley Dec 10, 2020
cba668a
fix(persist-localstorage): add ssr-safety
tannerlinsley Dec 10, 2020
cc99426
docs: fix typos in migration and queries guide (#1387)
flextremedev Dec 10, 2020
67af4cb
docs(typos): fix typos in mutations guide (#1392)
amen-souissi Dec 11, 2020
4965a11
docs: update migration guide
tannerlinsley Dec 11, 2020
aedf2a8
Merge branch 'beta' of https://github.com/tannerlinsley/react-query i…
tannerlinsley Dec 11, 2020
270dbb8
docs: update comparison
tannerlinsley Dec 11, 2020
5262c16
chore: remove vercel.json
tannerlinsley Dec 11, 2020
d69ed17
Merge branch 'master' into beta
tannerlinsley Dec 11, 2020
4c85af2
docs: update comparison
tannerlinsley Dec 11, 2020
67f77ae
Update logo.sketch
tannerlinsley Dec 12, 2020
7f172a0
feat: reset query utils (#1375)
tannerlinsley Dec 12, 2020
88d089c
types: fix mutation context type
boschni Dec 12, 2020
9883c41
fix: isFetched and isFetchedAfterMount should include failed fetches
boschni Dec 12, 2020
12d6714
docs: Persist localstorage plugin
tannerlinsley Dec 13, 2020
df530d6
feat: resetQueries refetches active queries (#1397)
aaronjensen Dec 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"plugins": ["@typescript-eslint", "import"],
"extends": [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/typescript",
"react-app",
"prettier"
],
Expand All @@ -26,6 +27,10 @@
"ignoreParameters": true
}
],
"no-shadow": "error"
"no-shadow": "error",
"import/no-cycle": "error",
"import/no-unresolved": "error",
"import/no-unused-modules": ["off", { "unusedExports": true }],
"no-redeclare": "off"
}
}
4 changes: 2 additions & 2 deletions .github/workflows/test-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches:
- 'master'
- 'next'
- 'beta'
- '1.x'
pull_request:

Expand Down Expand Up @@ -38,7 +38,7 @@ jobs:
registry-url: https://registry.npmjs.org/
- name: Install dependencies
uses: bahmutov/npm-install@v1
- run: yarn build && yarn build:types
- run: yarn build
- run: npx semantic-release@17
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
node_modules

# builds
types
build
dist
lib
es
artifacts
.rpt2_cache
coverage
*.tgz

# misc
.DS_Store
Expand All @@ -31,5 +33,3 @@ stats-hydration.json
stats-react.json
stats.html
.vscode/settings.json

types
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Enjoy this library? Try the entire [TanStack](https://tanstack.com)! [React Tabl
- Load-More + Infinite Scroll Queries w/ Scroll Recovery
- Request Cancellation
- [React Suspense](https://reactjs.org/docs/concurrent-mode-suspense.html) + Fetch-As-You-Render Query Prefetching
- [Dedicated Devtools (React Query Devtools)](https://github.com/tannerlinsley/react-query-devtools)
- [Dedicated Devtools
- <a href="https://bundlephobia.com/result?p=react-query@latest" target="\_parent">
<img alt="" src="https://badgen.net/bundlephobia/minzip/react-query@latest" />
</a> (depending on features imported)
Expand Down Expand Up @@ -80,4 +80,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

<!-- Force 1 -->
<!-- Force 2 -->
6 changes: 6 additions & 0 deletions core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"internal": true,
"main": "../lib/core/index.js",
"module": "../es/core/index.js",
"types": "../types/core/index.d.ts"
}
6 changes: 6 additions & 0 deletions devtools/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"internal": true,
"main": "../lib/devtools/index.js",
"module": "../es/devtools/index.js",
"types": "../types/devtools/index.d.ts"
}
27 changes: 10 additions & 17 deletions docs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,21 @@ const remarkPlugins = [
module.exports = optimizedImages({
pageExtensions: ['jsx', 'js', 'mdx', 'md'],
env: {
GA_TRACKING_ID: process.env.GA_TRACKING_ID || '',
NEXT_PUBLIC_GA_TRACKING_ID: process.env.GA_TRACKING_ID || '',
SENTRY_RELEASE: process.env.VERCEL_GITHUB_COMMIT_SHA || '',
},
async redirects() {
return [
{
source: '/docs/:any*',
destination: '/:any*', // Matched parameters can be used in the destination
permanent: true,
},
]
},
experimental: {
plugins: true,
modern: true,
rewrites() {
return [
{
source: '/feed.xml',
destination: '/_next/static/feed.xml',
},
{
source: '/docs{/}?',
destination: '/docs/overview',
},
{
source: '/docs/tag/:tag{/}?',
destination: '/docs/tag/:tag/overview',
},
]
},
},
webpack: (config, { dev, isServer, ...options }) => {
config.module.rules.push({
Expand Down
46 changes: 23 additions & 23 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,39 @@
"dependencies": {
"@babel/preset-typescript": "^7.10.4",
"@docsearch/react": "1.0.0-alpha.14",
"@mdx-js/loader": "^1.5.1",
"@mdx-js/mdx": "^1.5.1",
"@mdx-js/react": "^1.5.1",
"@mdx-js/loader": "^1.6.18",
"@mdx-js/mdx": "^1.6.18",
"@mdx-js/react": "^1.6.18",
"@mdx-js/tag": "^0.20.3",
"@next/mdx": "^9.4.0",
"@next/plugin-google-analytics": "^9.4.4",
"@next/mdx": "^9.5.3",
"@next/plugin-google-analytics": "^9.5.3",
"@reactions/component": "^2.0.2",
"@zeit/fetch": "^6.0.0",
"@zeit/react-jsx-parser": "^2.0.0",
"async-sema": "^3.1.0",
"body-scroll-lock": "^3.0.1",
"body-scroll-lock": "^3.1.5",
"classnames": "^2.2.6",
"copy-to-clipboard": "^3.3.1",
"date-fns": "^2.12.0",
"date-fns": "^2.16.1",
"docsearch.js": "^2.6.3",
"framer-motion": "^1.11.1",
"gray-matter": "^4.0.2",
"imagemin-mozjpeg": "^9.0.0",
"imagemin-optipng": "^8.0.0",
"intersection-observer": "^0.10.0",
"isomorphic-unfetch": "^3.0.0",
"next": "^9.4.4",
"next-images": "^1.4.0",
"next-optimized-images": "^2.6.1",
"node-fetch": "^2.6.0",
"prismjs": "^1.20.0",
"next": "^9.5.3",
"next-images": "^1.5.0",
"next-optimized-images": "^2.6.2",
"node-fetch": "^2.6.1",
"prismjs": "^1.21.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-icons": "^3.9.0",
"react-icons": "^3.11.0",
"react-live": "^2.2.2",
"rehype-format": "^3.0.1",
"rehype-stringify": "^7.0.0",
"remark": "^12.0.0",
"remark": "^12.0.1",
"remark-autolink-headings": "^6.0.0",
"remark-emoji": "^2.1.0",
"remark-footnotes": "^1.0.0",
Expand All @@ -54,26 +54,26 @@
"remark-slug": "^6.0.0",
"remark-toc": "^7.0.0",
"remark-unwrap-images": "^2.0.0",
"scroll-into-view-if-needed": "^2.2.24",
"scroll-into-view-if-needed": "^2.2.26",
"semver-regex": "^3.1.1",
"unist-util-visit": "^2.0.2"
"unist-util-visit": "^2.0.3"
},
"devDependencies": {
"@babel/cli": "^7.10.4",
"@babel/core": "^7.10.4",
"@babel/plugin-transform-typescript": "^7.10.4",
"@babel/cli": "^7.11.6",
"@babel/core": "^7.11.6",
"@babel/plugin-transform-typescript": "^7.11.0",
"@babel/preset-react": "^7.10.4",
"@tailwindcss/ui": "^0.3.0",
"algoliasearch": "3.35.1",
"babel-preset-react-app": "^9.1.2",
"dotenv-load": "^2.0.0",
"github-slugger": "^1.3.0",
"md5": "^2.2.1",
"md5": "^2.3.0",
"mdast-util-to-string": "^1.1.0",
"postcss-preset-env": "^6.7.0",
"remark-parse": "^8.0.2",
"tailwindcss": "^1.4.6",
"unified": "^9.0.0",
"remark-parse": "^8.0.3",
"tailwindcss": "^1.8.10",
"unified": "^9.2.0",
"webp-loader": "^0.6.0"
},
"engines": {
Expand Down
27 changes: 16 additions & 11 deletions docs/src/components/DocsPageFooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ function areEqual(prevProps, props) {
}

export const DocsPageFooter = React.memo(({ route, prevRoute, nextRoute }) => {
const editUrl = `${siteConfig.editUrl}${route?.editUrl || route?.path}`
const editUrl =
route?.editUrl || route?.path
? `${siteConfig.editUrl}${route?.editUrl || route?.path}`
: null

return (
<>
Expand Down Expand Up @@ -45,16 +48,18 @@ export const DocsPageFooter = React.memo(({ route, prevRoute, nextRoute }) => {
</div>
</div>

<div className="mb-8">
<a
href={editUrl}
target="_blank"
rel="noopener noreferrer"
className="text-gray-600 underline"
>
Edit this page on GitHub
</a>
</div>
{editUrl ? (
<div className="mb-8">
<a
href={editUrl}
target="_blank"
rel="noopener noreferrer"
className="text-gray-600 underline"
>
Edit this page on GitHub
</a>
</div>
) : null}

<div className="py-8 md:flex md:items-center md:py-8 border-t border-b">
<div className="font-semibold text-xl mr-4 text-center mb-4 md:mb-0 md:text-left">
Expand Down
6 changes: 3 additions & 3 deletions docs/src/components/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ export const Footer = props => {
</h4>
<ul className="mt-4">
<li>
<Link href="/docs/overview">
<Link href="/overview">
<a className="text-base leading-6 text-gray-500 hover:text-gray-900">
Docs
</a>
</Link>
</li>
<li className="mt-4">
<Link href="/docs/examples/simple">
<Link href="/examples/simple">
<a className="text-base leading-6 text-gray-500 hover:text-gray-900">
Examples
</a>
</Link>
</li>
<li className="mt-4">
<Link href="/docs/api">
<Link href="/api/useQuery">
<a className="text-base leading-6 text-gray-500 hover:text-gray-900">
API Reference
</a>
Expand Down
7 changes: 3 additions & 4 deletions docs/src/components/LayoutDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export const LayoutDocs = props => {
/>
<div className="block">
<>

<div className="container mx-auto pb-12 pt-6 content">
<div className="flex relative">
{!isMobile && (
Expand All @@ -89,7 +88,7 @@ export const LayoutDocs = props => {
)}

<div className={s['markdown'] + ' w-full docs'}>
<h1>{props.meta.title}</h1>
<h1 id="_top">{props.meta.title}</h1>
<MDXProvider components={MDXComponents}>
{props.children}
</MDXProvider>
Expand All @@ -107,11 +106,11 @@ export const LayoutDocs = props => {
width: 200,
}}
>
<div className="sticky top-24 ">
<div className="sticky top-24 overflow-y-auto">
<h4 className="font-semibold uppercase text-sm mb-2 mt-2 text-gray-500">
On this page
</h4>
<Toc />
<Toc title={props.meta.title} />
</div>
</div>
)}
Expand Down
4 changes: 2 additions & 2 deletions docs/src/components/Nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ export const Nav = () => (
<div className="flex flex-grow items-center justify-between w-3/4 md:w-auto md:justify-end space-x-4 md:space-x-8 h-16">
<div className="flex space-x-4 md:space-x-8 text-sm md:text-base">
<div>
<Link href="/docs/overview">
<Link href="/overview">
<a className="leading-6 font-medium">Docs</a>
</Link>
</div>
<div>
<Link href="/docs/examples/simple">
<Link href="/examples/simple">
<a className="leading-6 font-medium">Examples</a>
</Link>
</div>
Expand Down
22 changes: 12 additions & 10 deletions docs/src/components/Toc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ import styles from './Toc.module.css'
const TOP_OFFSET = 100

function getHeaderAnchors() {
return Array.prototype.filter.call(
document.getElementsByClassName('anchor'),
function (testElement) {
return (
testElement.parentNode.nodeName === 'H2' ||
testElement.parentNode.nodeName === 'H3'
)
}
)
return [
...document.getElementsByTagName('H1'),
...[...document.getElementsByClassName('anchor')].filter(
el => el.parentNode.nodeName === 'H2' || el.parentNode.nodeName === 'H3'
),
].filter(Boolean)
}

function getHeaderDataFromAnchors(el) {
Expand All @@ -24,7 +21,7 @@ function getHeaderDataFromAnchors(el) {
}
}

export const Toc = () => {
export const Toc = ({ title }) => {
const headings = useTocHighlight(
styles.contents__link,
styles['contents__link--active'],
Expand All @@ -36,6 +33,11 @@ export const Toc = () => {

return (
<ul className="space-y-3">
<li className="text-sm">
<a className={styles.contents__link} href="#_top">
{title}
</a>
</li>
{headings &&
headings.length > 0 &&
headings.map((h, i) =>
Expand Down
Loading