Compare commits

..

2 Commits

6 changed files with 64 additions and 1300 deletions
+9 -1256
View File
File diff suppressed because it is too large Load Diff
+1 -4
View File
@@ -4,13 +4,12 @@
"version": "0.0.0", "version": "0.0.0",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build", "build": "vite build",
"lint": "eslint .", "lint": "eslint .",
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {
"info": "^1.0.0",
"react": "^19.1.0", "react": "^19.1.0",
"react-dom": "^19.1.0" "react-dom": "^19.1.0"
}, },
@@ -23,8 +22,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"
} }
} }
+38 -17
View File
@@ -1,29 +1,50 @@
import styles from './styles/App.module.scss' import { useState, useReducer } from 'react'
import React, { useState, useCallback } from 'react'
function CounterButton({label, onClick}) { function counterReducer(state, action) {
return ( switch (action.type) {
<button onClick={onClick} className={styles.counter_button}>{label}</button> case 'increment':
) return state + 1
case 'decrement':
return state - 1
case 'reset':
return 0
case 'set_value':
return action.value
default:
return state
}
} }
function CounterDisplay({value}) {
return (<div className={styles.counter_display}> function Counter() {
Значение счетчика: <b>{value}</b> const [count, dispatch] = useReducer(counterReducer,0);
</div>)
return (
<div>
<span>Счетчик: {count}</span>
<button onClick={()=> dispatch({type: 'increment'})}>+</button>
<button onClick={()=> dispatch({type: 'decrement'})}>-</button>
<button onClick={()=> dispatch({type: 'reset'})}>reset</button>
<button onClick={()=> dispatch({type: 'set_value', value: 5})}>set 5</button>
</div>
)
} }
function App() { function App() {
const [counter,setCounter] = useState(0); const [tasks, setTasks] = useState([])
const [filter, setFilter] = useState('all')
const [sortBy,setSortBy] = useState('date')
const addTask = newTask => {
setTasks([...tasks,newTask])
}
const increment = () => setCounter(prev => prev + 1);
const decrement = () => setCounter(prev => prev - 1);
return ( return (
<> <>
<h2>Практика по созданию счетчика с колбэками</h2> {/* Добавьте тестовый контент для проверки */}
<CounterButton label="Увеличить" onClick={increment} /> <h1>Hello, React!</h1>
<CounterButton label="уменьшить" onClick={decrement} /> <Counter />
<CounterDisplay value={counter} />
</> </>
) )
} }
+15
View File
@@ -0,0 +1,15 @@
.container {
/* display: flex;
flex-direction: column;
flex-wrap: nowrap;*/
height: 500px;
overflow: auto;
border: 1px solid black;
}
.item {
font-size: 16pt;
border: 1px dotted gray;
/*margin: 5px 10px;
padding: 10px;*/
border-radius: 5px;
}
+1 -1
View File
@@ -1,6 +1,6 @@
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(
-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;
}
}