Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 964b7dae29 |
Generated
+69
-1
@@ -9,7 +9,9 @@
|
|||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"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",
|
||||||
@@ -1600,6 +1602,19 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"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": {
|
"node_modules/cross-spawn": {
|
||||||
"version": "7.0.6",
|
"version": "7.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
|
||||||
@@ -2461,6 +2476,15 @@
|
|||||||
"react": "^19.1.0"
|
"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": {
|
"node_modules/react-refresh": {
|
||||||
"version": "0.17.0",
|
"version": "0.17.0",
|
||||||
"resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.17.0.tgz",
|
"resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.17.0.tgz",
|
||||||
@@ -2471,6 +2495,44 @@
|
|||||||
"node": ">=0.10.0"
|
"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": {
|
"node_modules/resolve-from": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz",
|
||||||
@@ -2544,6 +2606,12 @@
|
|||||||
"semver": "bin/semver.js"
|
"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": {
|
"node_modules/shebang-command": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
|
||||||
|
|||||||
+3
-1
@@ -11,7 +11,9 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"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",
|
||||||
|
|||||||
+19
-60
@@ -1,68 +1,27 @@
|
|||||||
import React, { useState, useReducer, useRef, memo } from 'react'
|
import { Suspense, lazy } from 'react'
|
||||||
|
import { ErrorBoundary } from 'react-error-boundary'
|
||||||
|
|
||||||
function tasksReducer(state, action) {
|
const LazyComponent = lazy(() => import('./MyComponent'))
|
||||||
switch(action.type) {
|
|
||||||
case 'ADD_TASK':
|
|
||||||
return [...state, action.payload]
|
|
||||||
case 'TOGGLE_TASK':
|
|
||||||
return state.map(task => task.id === action.payload ? {...task, complite: !task.complite} : task)
|
|
||||||
case 'REMOVE_TASK':
|
|
||||||
return state.filter(task => task.id !== action.payload)
|
|
||||||
default:
|
|
||||||
return state
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const TaskList = memo(function TaskList({tasks, onToggle, onRemove}) {
|
function ErrorFallBack({error, resetErrorBoundary }) {
|
||||||
console.log("Rendred")
|
|
||||||
return (
|
return (
|
||||||
<ul>
|
<div>
|
||||||
{tasks.map(({id, text, complite}) => (
|
<h2>Что то сломалось</h2>
|
||||||
<li key={id}
|
<button onClick={resetErrorBoundary}></button>
|
||||||
style={{textDecoration: complite ? 'line-through' : 'none' }}>
|
|
||||||
<input type="checkbox" checked={complite} onChange={()=>onToggle(id)} />
|
|
||||||
{text}
|
|
||||||
<button onClick={()=> onRemove(id)} style={{marginLeft: 10}}>
|
|
||||||
Удалить
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
function App() {
|
|
||||||
const [tasks, dispatch] = useReducer(tasksReducer,[])
|
|
||||||
const [input,setInput] = useState('')
|
|
||||||
const [error,setError] = useState('')
|
|
||||||
const inputRef = useRef(null)
|
|
||||||
|
|
||||||
const addTask = () => {
|
|
||||||
if (input.trim() === '') {
|
|
||||||
setError('Пустой текст задачи')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
setError('')
|
|
||||||
dispatch({
|
|
||||||
type: 'ADD_TASK',
|
|
||||||
payload: {id: Date.now(), text: input.trim(), complite: false }
|
|
||||||
})
|
|
||||||
setInput('')
|
|
||||||
inputRef.current.focus()
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div style={{padding: 20}}>
|
|
||||||
<h1>Список дел</h1>
|
|
||||||
<input ref={inputRef} value={input} onChange={e => setInput(e.target.value)} />
|
|
||||||
<button onClick={addTask}>Добавить</button>
|
|
||||||
{error && <p style={{color: 'red'}}>{error}</p>}
|
|
||||||
|
|
||||||
<TaskList tasks={tasks}
|
|
||||||
onToggle={id => dispatch({type: 'TOGGLE_TASK', payload: id})}
|
|
||||||
onRemove={id => dispatch({type: 'REMOVE_TASK', payload: id})} />
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function App() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ErrorBoundary FallBackComponent={ErrorFallBack}>
|
||||||
|
<Suspense fallback={<div>Загрузка ...</div>}>
|
||||||
|
<LazyComponent />
|
||||||
|
</Suspense>
|
||||||
|
</ErrorBoundary>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export default App
|
export default App
|
||||||
|
|||||||
Reference in New Issue
Block a user