Compare commits

..

1 Commits

Author SHA1 Message Date
laktionov-as de33066cbe Практика 2026-06-11 20:13:10 +03:00
6 changed files with 70 additions and 1304 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" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {
"info": "^1.0.0", "immer": "^11.1.8",
"react": "^19.1.0", "react": "^19.1.0",
"react-dom": "^19.1.0" "react-dom": "^19.1.0"
}, },
@@ -23,8 +23,6 @@
"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"
} }
} }
+41 -21
View File
@@ -1,29 +1,49 @@
import styles from './styles/App.module.scss' import React, { useState, useEffect } from 'react'
import React, { useState, useCallback } from 'react' import { produce } from 'immer'
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() { 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 ( return (
<> <>
<h2>Практика по созданию счетчика с колбэками</h2> <h1>Практика по созданию списка задач</h1>
<CounterButton label="Увеличить" onClick={increment} /> <input value={input} onChange={e=>setInput(e.target.value)} />
<CounterButton label="уменьшить" onClick={decrement} /> <button onClick={addTask}>Добавить</button>
<CounterDisplay value={counter} /> <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
+1 -3
View File
@@ -1,10 +1,8 @@
import { StrictMode } from 'react' import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client' import { createRoot } from 'react-dom/client'
// удаляем import './index.css'
import App from './App.jsx' import App from './App.jsx'
createRoot(document.getElementById('root')).render( createRoot(document.getElementById('root')).render(
<StrictMode>
<App /> <App />
</StrictMode>
) )
-22
View File
@@ -1,22 +0,0 @@
.container {
display:flex;
flex-direction: row;
border: 1px solid black;
border-radius: 5px;
margin-bottom: 10px;
p {
padding: 5px 10px;
}
}
.counter {
&_display{
border: 1px solid black;
border-width: 3px;
border-radius: 10px;
padding: 10px;
width: 300px;
}
&_button{
padding: 10px;
}
}