Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 35431f57d9 | |||
| 8a15a26ff6 |
Generated
+28
-69
@@ -8,10 +8,9 @@
|
||||
"name": "store-client",
|
||||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"@tanstack/react-query": "^5.100.14",
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0",
|
||||
"react-error-boundary": "^6.1.2",
|
||||
"react-router-dom": "^7.17.0"
|
||||
"react-dom": "^19.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.25.0",
|
||||
@@ -1306,6 +1305,32 @@
|
||||
"win32"
|
||||
]
|
||||
},
|
||||
"node_modules/@tanstack/query-core": {
|
||||
"version": "5.100.14",
|
||||
"resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.100.14.tgz",
|
||||
"integrity": "sha512-5X41dGpxgeaHISCRW2oYwcSycZeULZzAunaudXT9ov1KOTj9xwt0CH6hbwqP1/z74ZWF7rYFnDpyYH07XFcZew==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/tannerlinsley"
|
||||
}
|
||||
},
|
||||
"node_modules/@tanstack/react-query": {
|
||||
"version": "5.100.14",
|
||||
"resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-5.100.14.tgz",
|
||||
"integrity": "sha512-oOr6aRdSFEwWhzxEkD/9ZcItM3+LjBSkeVmadWKwUssAHTsqd/7bOjWrX4AbvEkoEhgAxzN0Xk6H/aYzXiYBAw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@tanstack/query-core": "5.100.14"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/tannerlinsley"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^18 || ^19"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/babel__core": {
|
||||
"version": "7.20.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz",
|
||||
@@ -1602,19 +1627,6 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/cookie": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-1.1.1.tgz",
|
||||
"integrity": "sha512-ei8Aos7ja0weRpFzJnEA9UHJ/7XQmqglbRwnf2ATjcB9Wq874VKH9kfjjirM6UhU2/E5fFYadylyhFldcqSidQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/cross-spawn": {
|
||||
"version": "7.0.6",
|
||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
|
||||
@@ -2476,15 +2488,6 @@
|
||||
"react": "^19.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/react-error-boundary": {
|
||||
"version": "6.1.2",
|
||||
"resolved": "https://registry.npmjs.org/react-error-boundary/-/react-error-boundary-6.1.2.tgz",
|
||||
"integrity": "sha512-3DpCr5HVdZ0caUjYE/kIHBEJN0mNP3ZCgf16c48uJ5TbWjorKVp+YG8W3XqlJ7vJAVNw6wNIImyPXmFydwmyng==",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"react": "^18.0.0 || ^19.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/react-refresh": {
|
||||
"version": "0.17.0",
|
||||
"resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.17.0.tgz",
|
||||
@@ -2495,44 +2498,6 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/react-router": {
|
||||
"version": "7.17.0",
|
||||
"resolved": "https://registry.npmjs.org/react-router/-/react-router-7.17.0.tgz",
|
||||
"integrity": "sha512-FDELK7rTMlCHO5+reyXsPlmfr7N1F91lPHsWYfMEGQm/KQ+F4JFM8jGoeQDmDvdTs93Fw9aSilH+uKRb4/jXvQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"cookie": "^1.0.1",
|
||||
"set-cookie-parser": "^2.6.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=18",
|
||||
"react-dom": ">=18"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"react-dom": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/react-router-dom": {
|
||||
"version": "7.17.0",
|
||||
"resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-7.17.0.tgz",
|
||||
"integrity": "sha512-fyU2yjGups/hE6Xz0I5ZYbVL8Gx29eCjgpHaRaTaVU+OOAdfRX05KsvyRm0GO8YQwOkhpU3MurW1jyMUJn+zSw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"react-router": "7.17.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=18",
|
||||
"react-dom": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/resolve-from": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz",
|
||||
@@ -2606,12 +2571,6 @@
|
||||
"semver": "bin/semver.js"
|
||||
}
|
||||
},
|
||||
"node_modules/set-cookie-parser": {
|
||||
"version": "2.7.2",
|
||||
"resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-2.7.2.tgz",
|
||||
"integrity": "sha512-oeM1lpU/UvhTxw+g3cIfxXHyJRc/uidd3yK1P242gzHds0udQBYzs3y8j4gCCW+ZJ7ad0yctld8RYO+bdurlvw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/shebang-command": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
|
||||
|
||||
+2
-3
@@ -10,10 +10,9 @@
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tanstack/react-query": "^5.100.14",
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0",
|
||||
"react-error-boundary": "^6.1.2",
|
||||
"react-router-dom": "^7.17.0"
|
||||
"react-dom": "^19.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.25.0",
|
||||
|
||||
+82
-14
@@ -1,25 +1,93 @@
|
||||
import { Suspense, lazy } from 'react'
|
||||
import { ErrorBoundary } from 'react-error-boundary'
|
||||
import React, {useState, useEffect, useRef } from 'react'
|
||||
//import { useQuery } from '@tanstack/react-query'
|
||||
|
||||
const LazyComponent = lazy(() => import('./MyComponent'))
|
||||
function useWindowWidth() {
|
||||
const [width,setWidth] = useState(window.innerWidth)
|
||||
|
||||
useEffect(() => {
|
||||
const handleResize = () => setWidth(window.innerWidth);
|
||||
window.addEventListener('resize',handleResize);
|
||||
return () => window.removeEventListener('resize',handleResize);
|
||||
},[])
|
||||
|
||||
return width
|
||||
}
|
||||
|
||||
function ErrorFallBack({error, resetErrorBoundary }) {
|
||||
return (
|
||||
<div>
|
||||
<h2>Что то сломалось</h2>
|
||||
<button onClick={resetErrorBoundary}></button>
|
||||
</div>
|
||||
function useLocalStorage(key, initValue) {
|
||||
const [value, setValue] = useState(()=>{
|
||||
const stored = localStorage.getItem(key);
|
||||
return stored !== null ? JSON.parse(stored) : initValue
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem(key, JSON.stringify(value))
|
||||
},[key, value])
|
||||
|
||||
return [value,setValue]
|
||||
}
|
||||
/*
|
||||
function useUserData(userId) {
|
||||
return useQuery(
|
||||
['user',userId],
|
||||
() => fetch(`/api/user/${userId}`).then(res => res.json()),
|
||||
{refetchOnWindowFocus: false}
|
||||
)
|
||||
}*/
|
||||
|
||||
function useInput(initValue, validate) {
|
||||
const [value, setValue] = useState(initValue);
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
const onChange = e => {
|
||||
const newValue = e.target.value
|
||||
setValue(newValue)
|
||||
if (validate) {
|
||||
const validationResult = validate(newValue)
|
||||
setError(validationResult)
|
||||
}
|
||||
}
|
||||
|
||||
return { value, error, onChange }
|
||||
}
|
||||
|
||||
function useInterval(callback, delay) {
|
||||
const savedCallback = useRef()
|
||||
|
||||
useEffect(()=>{
|
||||
savedCallback.current = callback
|
||||
},[callback]);
|
||||
|
||||
useEffect(()=>{
|
||||
if (delay == null) return
|
||||
const id = setInterval(()=>{
|
||||
savedCallback.current()
|
||||
},delay);
|
||||
return () => clearInterval(id);
|
||||
},[delay])
|
||||
}
|
||||
|
||||
function App() {
|
||||
const width = useWindowWidth();
|
||||
const [theme, setTheme] = useLocalStorage('theme','light');
|
||||
|
||||
const username = useInput(
|
||||
'',
|
||||
value => value.length < 3 ? 'минимум 3 символа' : null
|
||||
)
|
||||
|
||||
return (
|
||||
<>
|
||||
<ErrorBoundary FallBackComponent={ErrorFallBack}>
|
||||
<Suspense fallback={<div>Загрузка ...</div>}>
|
||||
<LazyComponent />
|
||||
</Suspense>
|
||||
</ErrorBoundary>
|
||||
<h1>Hello, React!{width}</h1>
|
||||
<button onClick={()=>{
|
||||
setTheme(theme === 'light' ? 'dark' : 'light')
|
||||
}}>
|
||||
Сменить тему
|
||||
</button>
|
||||
<p><input type="text"
|
||||
value={username.value}
|
||||
onChange={username.onChange} />
|
||||
{ username.error ? username.error : '' }
|
||||
</p>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user