Compare commits

..

7 Commits

3 changed files with 1268 additions and 84 deletions
+1246 -67
View File
File diff suppressed because it is too large Load Diff
+4 -3
View File
@@ -10,10 +10,9 @@
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {
"info": "^1.0.0",
"react": "^19.1.0", "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": { "devDependencies": {
"@eslint/js": "^9.25.0", "@eslint/js": "^9.25.0",
@@ -24,6 +23,8 @@
"eslint-plugin-react-hooks": "^5.2.0", "eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.19", "eslint-plugin-react-refresh": "^0.4.19",
"globals": "^16.0.0", "globals": "^16.0.0",
"sass": "^1.99.0",
"sass-embedded": "^1.99.0",
"vite": "^6.3.5" "vite": "^6.3.5"
} }
} }
+18 -14
View File
@@ -1,25 +1,29 @@
import { Suspense, lazy } from 'react' import styles from './styles/App.module.scss'
import { ErrorBoundary } from 'react-error-boundary' import React, { useState, useCallback } from 'react'
const LazyComponent = lazy(() => import('./MyComponent')) function CounterButton({label, onClick}) {
function ErrorFallBack({error, resetErrorBoundary }) {
return ( return (
<div> <button onClick={onClick} className={styles.counter_button}>{label}</button>
<h2>Что то сломалось</h2>
<button onClick={resetErrorBoundary}></button>
</div>
) )
} }
function CounterDisplay({value}) {
return (<div className={styles.counter_display}>
Значение счетчика: <b>{value}</b>
</div>)
}
function App() { function App() {
const [counter,setCounter] = useState(0);
const increment = () => setCounter(prev => prev + 1);
const decrement = () => setCounter(prev => prev - 1);
return ( return (
<> <>
<ErrorBoundary FallBackComponent={ErrorFallBack}> <h2>Практика по созданию счетчика с колбэками</h2>
<Suspense fallback={<div>Загрузка ...</div>}> <CounterButton label="Увеличить" onClick={increment} />
<LazyComponent /> <CounterButton label="уменьшить" onClick={decrement} />
</Suspense> <CounterDisplay value={counter} />
</ErrorBoundary>
</> </>
) )
} }