snapshot of https://github.com/TanStack/query.git (main, 2026-09-16; blobs > 131072B omitted)
This commit is contained in:
24
examples/react/shadow-dom/.gitignore
vendored
Normal file
24
examples/react/shadow-dom/.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
6
examples/react/shadow-dom/README.md
Normal file
6
examples/react/shadow-dom/README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# Example
|
||||
|
||||
To run this example:
|
||||
|
||||
- `pnpm install`
|
||||
- `pnpm run dev`
|
||||
9
examples/react/shadow-dom/eslint.config.js
Normal file
9
examples/react/shadow-dom/eslint.config.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import { tanstackConfig } from '@tanstack/eslint-config'
|
||||
import pluginQuery from '@tanstack/eslint-plugin-query'
|
||||
import pluginReact from '@eslint-react/eslint-plugin'
|
||||
|
||||
export default [
|
||||
...tanstackConfig,
|
||||
...pluginQuery.configs['flat/recommended'],
|
||||
pluginReact.configs.recommended,
|
||||
]
|
||||
13
examples/react/shadow-dom/index.html
Normal file
13
examples/react/shadow-dom/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + React + TS</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
23
examples/react/shadow-dom/package.json
Normal file
23
examples/react/shadow-dom/package.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "@tanstack/query-example-react-shadow-dom",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tanstack/react-query": "^5.102.8",
|
||||
"@tanstack/react-query-devtools": "^5.102.8",
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^19.0.1",
|
||||
"@types/react-dom": "^19.0.2",
|
||||
"@vitejs/plugin-react": "^4.3.4",
|
||||
"typescript": "5.8.3",
|
||||
"vite": "^6.4.1"
|
||||
}
|
||||
}
|
||||
34
examples/react/shadow-dom/src/DogList.tsx
Normal file
34
examples/react/shadow-dom/src/DogList.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
|
||||
type DogsResp = {
|
||||
message: {
|
||||
[dog: string]: Array<string>
|
||||
}
|
||||
}
|
||||
|
||||
export const DogList = () => {
|
||||
const { data, status } = useQuery<DogsResp>({
|
||||
queryKey: ['dogs'],
|
||||
queryFn: async () => {
|
||||
const resp = await fetch('https://dog.ceo/api/breeds/list/all')
|
||||
if (resp.ok) {
|
||||
return resp.json()
|
||||
}
|
||||
throw new Error('something went wrong')
|
||||
},
|
||||
})
|
||||
|
||||
if (status === 'pending') return 'Loading...'
|
||||
|
||||
if (status === 'error') return 'Error!'
|
||||
|
||||
const dogs = Object.keys(data.message)
|
||||
|
||||
return (
|
||||
<div>
|
||||
{dogs.map((dog) => (
|
||||
<div key={dog}>{dog}</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
68
examples/react/shadow-dom/src/index.css
Normal file
68
examples/react/shadow-dom/src/index.css
Normal file
@@ -0,0 +1,68 @@
|
||||
:root {
|
||||
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme: light dark;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 500;
|
||||
color: #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
place-items: center;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3.2em;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.6em 1.2em;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
background-color: #1a1a1a;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.25s;
|
||||
}
|
||||
button:hover {
|
||||
border-color: #646cff;
|
||||
}
|
||||
button:focus,
|
||||
button:focus-visible {
|
||||
outline: 4px auto -webkit-focus-ring-color;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
color: #213547;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
a:hover {
|
||||
color: #747bff;
|
||||
}
|
||||
button {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
}
|
||||
34
examples/react/shadow-dom/src/main.tsx
Normal file
34
examples/react/shadow-dom/src/main.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import './index.css'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
|
||||
import { DogList } from './DogList'
|
||||
|
||||
const appRoot = document.getElementById('root')
|
||||
if (!appRoot) throw new Error('Missing #root element')
|
||||
|
||||
const queryClient = new QueryClient()
|
||||
const shadowRoot = appRoot.attachShadow({ mode: 'open' })
|
||||
const root = ReactDOM.createRoot(shadowRoot)
|
||||
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<div
|
||||
style={{
|
||||
width: '100vw',
|
||||
padding: '30px',
|
||||
}}
|
||||
>
|
||||
<h2>Dog Breeds</h2>
|
||||
<DogList />
|
||||
</div>
|
||||
<ReactQueryDevtools
|
||||
initialIsOpen={false}
|
||||
buttonPosition="bottom-left"
|
||||
shadowDOMTarget={shadowRoot}
|
||||
/>
|
||||
</QueryClientProvider>
|
||||
</React.StrictMode>,
|
||||
)
|
||||
1
examples/react/shadow-dom/src/vite-env.d.ts
vendored
Normal file
1
examples/react/shadow-dom/src/vite-env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
||||
24
examples/react/shadow-dom/tsconfig.json
Normal file
24
examples/react/shadow-dom/tsconfig.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "Bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"include": ["src", "eslint.config.js"]
|
||||
}
|
||||
7
examples/react/shadow-dom/vite.config.ts
Normal file
7
examples/react/shadow-dom/vite.config.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
})
|
||||
Reference in New Issue
Block a user