Compare commits

..

8 Commits

6 changed files with 1304 additions and 70 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"
}
}
+20 -40
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 addTask = () => {
if(!input.trim()) return
const increment = () => setCounter(prev => prev + 1);
const decrement = () => setCounter(prev => prev - 1);
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
+3 -1
View File
@@ -1,8 +1,10 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
// удаляем import './index.css'
import App from './App.jsx'
createRoot(document.getElementById('root')).render(
<StrictMode>
<App />
</StrictMode>
)
+22
View File
@@ -0,0 +1,22 @@
.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;
}
}