Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 964b7dae29 |
Generated
+69
-1
@@ -9,7 +9,9 @@
|
||||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0"
|
||||
"react-dom": "^19.1.0",
|
||||
"react-error-boundary": "^6.1.2",
|
||||
"react-router-dom": "^7.17.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.25.0",
|
||||
@@ -1600,6 +1602,19 @@
|
||||
"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",
|
||||
@@ -2461,6 +2476,15 @@
|
||||
"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",
|
||||
@@ -2471,6 +2495,44 @@
|
||||
"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",
|
||||
@@ -2544,6 +2606,12 @@
|
||||
"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",
|
||||
|
||||
+4
-2
@@ -4,14 +4,16 @@
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0"
|
||||
"react-dom": "^19.1.0",
|
||||
"react-error-boundary": "^6.1.2",
|
||||
"react-router-dom": "^7.17.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.25.0",
|
||||
|
||||
+11
-84
@@ -1,98 +1,25 @@
|
||||
import { useState, useRef, useEffect } from 'react'
|
||||
import { Suspense, lazy } from 'react'
|
||||
import { ErrorBoundary } from 'react-error-boundary'
|
||||
|
||||
function Example() {
|
||||
const myRef = useRef(null);
|
||||
const counterRef = useRef(0);
|
||||
const [text, setText] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
myRef.current?.focus();
|
||||
},[]);
|
||||
|
||||
const handlerFocus = () => {
|
||||
if(myRef.current) {
|
||||
myRef.current.focus();
|
||||
}
|
||||
};
|
||||
|
||||
const handlerChange = (event) => {
|
||||
setText(event.target.value);
|
||||
}
|
||||
counterRef.current += 1;
|
||||
return <div>
|
||||
<input ref={myRef} text="text" /><br />
|
||||
Количество рендров: {counterRef.current}<br />
|
||||
<input text="text" onChange={handlerChange} value={text} />
|
||||
<button onClick={handlerFocus}>Поставить фокус на поле</button>
|
||||
</div>
|
||||
}
|
||||
const LazyComponent = lazy(() => import('./MyComponent'))
|
||||
|
||||
function ClickCounter() {
|
||||
const countRef = useRef(0);
|
||||
|
||||
function handlerClick() {
|
||||
countRef.current += 1;
|
||||
//alert(`Нажали ${countRef.current} раз.`);
|
||||
}
|
||||
return <button onClick={handlerClick}>Нажать</button>;
|
||||
}
|
||||
|
||||
function TimerComponent() {
|
||||
const timerIdRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
timerIdRef.current = setTimeout(() => {
|
||||
alert("Прошло 3 секунды");
|
||||
}, 3000);
|
||||
return () => {
|
||||
clearTimeout(timerIdRef.current);
|
||||
}
|
||||
},[]);
|
||||
}
|
||||
|
||||
function PrevValue({ value }) {
|
||||
const prevValueRef = useRef();
|
||||
|
||||
useEffect(() => {
|
||||
prevValueRef.current = value;
|
||||
});
|
||||
function ErrorFallBack({error, resetErrorBoundary }) {
|
||||
return (
|
||||
<div>
|
||||
Текущее значение: {value} <br />
|
||||
Предыдущее значение: {prevValueRef.current}
|
||||
<h2>Что то сломалось</h2>
|
||||
<button onClick={resetErrorBoundary}></button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function ScrollList() {
|
||||
const listRef = useRef(null);
|
||||
|
||||
const scrollToBottom = () => {
|
||||
if(listRef.current) {
|
||||
listRef.current.scrollTop = listRef.current.scrollHeight;
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div ref={listRef}
|
||||
style={{height: 200, overflowY: 'auto', border: '1px solid black'}}>
|
||||
{[...Array(20)].map((_,i)=>(
|
||||
<div key={i}>Элемент № {i + 1}</div>
|
||||
))}
|
||||
</div>
|
||||
<button onClick={scrollToBottom}>Прокрутить вниз</button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
function App() {
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<h1>Hello, React!</h1>
|
||||
<ScrollList />
|
||||
<ErrorBoundary FallBackComponent={ErrorFallBack}>
|
||||
<Suspense fallback={<div>Загрузка ...</div>}>
|
||||
<LazyComponent />
|
||||
</Suspense>
|
||||
</ErrorBoundary>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4,5 +4,7 @@ import { createRoot } from 'react-dom/client'
|
||||
import App from './App.jsx'
|
||||
|
||||
createRoot(document.getElementById('root')).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user