Compare commits

..

7 Commits

5 changed files with 1281 additions and 69 deletions
+1255 -19
View File
File diff suppressed because it is too large Load Diff
+3 -1
View File
@@ -10,7 +10,7 @@
"preview": "vite preview"
},
"dependencies": {
"immer": "^11.1.8",
"info": "^1.0.0",
"react": "^19.1.0",
"react-dom": "^19.1.0"
},
@@ -23,6 +23,8 @@
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.19",
"globals": "^16.0.0",
"sass": "^1.99.0",
"sass-embedded": "^1.99.0",
"vite": "^6.3.5"
}
}
+21 -41
View File
@@ -1,49 +1,29 @@
import React, { useState, useEffect } from 'react'
import { produce } from 'immer'
import styles from './styles/App.module.scss'
import React, { useState, useCallback } from 'react'
function CounterButton({label, onClick}) {
return (
<button onClick={onClick} className={styles.counter_button}>{label}</button>
)
}
function CounterDisplay({value}) {
return (<div className={styles.counter_display}>
Значение счетчика: <b>{value}</b>
</div>)
}
function App() {
const [tasks,setTasks] = useState([])
const [input,setInput] = useState('')
const [counter,setCounter] = useState(0);
const increment = () => setCounter(prev => prev + 1);
const decrement = () => setCounter(prev => prev - 1);
const addTask = () => {
if(!input.trim()) return
setTasks(currentTasks => produce(currentTasks, draft => {
draft.push({
id: Date.now(),
text: input.trim(),
done: false
})
}))
setInput('')
}
const toggleTask = id => {
setTasks(currentTask => produce(currentTask, draft => {
const task = draft.find(t => t.id === id)
if(task) {
task.done = !task.done
}
}))
}
const removeTask = id => {
setTasks(currentTask => produce(currentTask, draft => {
const index = draft.findIndex(t => t.id === id)
if (index !== -1)
draft.splice(index,1)
}))
}
return (
<>
<h1>Практика по созданию списка задач</h1>
<input value={input} onChange={e=>setInput(e.target.value)} />
<button onClick={addTask}>Добавить</button>
<ul>{tasks.map(({id,text,done}) => (
<li key={id} style={{ textDecoration: done ? 'line-through' : 'none'}}>
<input type="checkbox" checked={done} onChange={()=> toggleTask(id)} />
{text}
<button onClick={() => removeTask(id)}>Удалить</button>
</li>
))}</ul>
<h2>Практика по созданию счетчика с колбэками</h2>
<CounterButton label="Увеличить" onClick={increment} />
<CounterButton label="уменьшить" onClick={decrement} />
<CounterDisplay value={counter} />
</>
)
}
-8
View File
@@ -1,8 +0,0 @@
export function MyComponent() {
return (
<>
<h1>Hello</h1>
</>
)
}
export default MyComponent
+2
View File
@@ -4,5 +4,7 @@ import { createRoot } from 'react-dom/client'
import App from './App.jsx'
createRoot(document.getElementById('root')).render(
<StrictMode>
<App />
</StrictMode>
)