Compare commits

..

1 Commits

Author SHA1 Message Date
laktionov-as de33066cbe Практика 2026-06-11 20:13:10 +03:00
5 changed files with 69 additions and 1281 deletions
+19 -1255
View File
File diff suppressed because it is too large Load Diff
+1 -3
View File
@@ -10,7 +10,7 @@
"preview": "vite preview"
},
"dependencies": {
"info": "^1.0.0",
"immer": "^11.1.8",
"react": "^19.1.0",
"react-dom": "^19.1.0"
},
@@ -23,8 +23,6 @@
"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"
}
}
+40 -20
View File
@@ -1,29 +1,49 @@
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>)
}
import React, { useState, useEffect } from 'react'
import { produce } from 'immer'
function App() {
const [counter,setCounter] = useState(0);
const [tasks,setTasks] = useState([])
const [input,setInput] = useState('')
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 (
<>
<h2>Практика по созданию счетчика с колбэками</h2>
<CounterButton label="Увеличить" onClick={increment} />
<CounterButton label="уменьшить" onClick={decrement} />
<CounterDisplay value={counter} />
<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>
</>
)
}
+8
View File
@@ -0,0 +1,8 @@
export function MyComponent() {
return (
<>
<h1>Hello</h1>
</>
)
}
export default MyComponent
-2
View File
@@ -4,7 +4,5 @@ import { createRoot } from 'react-dom/client'
import App from './App.jsx'
createRoot(document.getElementById('root')).render(
<StrictMode>
<App />
</StrictMode>
)