Compare commits

..

1 Commits

Author SHA1 Message Date
laktionov-as 43aeb40b20 i dont know 2026-06-18 18:53:17 +03:00
2 changed files with 31 additions and 52 deletions
+31 -37
View File
@@ -1,50 +1,44 @@
import { useState, useReducer } from 'react' import { useMutation, QueryClientProvider, QueryClient } from '@tanstack/react-query'
import PostAddForm from './components/PostAddForm'
function counterReducer(state, action) { /*
switch (action.type) { const mutation = useMutation({
case 'increment': mutationFn: newUser => {
return state + 1 fetch('https://jsonplaceholder.typicode.com/users', {
case 'decrement': method: 'GET',
return state - 1 headers: {'Content-type':'application/json'},
case 'reset': body: JSON.stringify(newUser),
return 0 }).then(res => res.json())
case 'set_value': }
return action.value })
default: */
return state
const createQueryClient = () => {
new QueryClient({
defaultOptions: {
queries: {
staleTime: 5 * 60*1000,
retry: 1,
gcTime: 10*60*1000,
refetchOnWindowFocus: false,
},
mutations: {
retry:0,
onError: error => {console.error('Mutation error:',error.message)}
} }
} }
})
function Counter() {
const [count, dispatch] = useReducer(counterReducer,0);
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 [tasks, setTasks] = useState([])
const [filter, setFilter] = useState('all')
const [sortBy,setSortBy] = useState('date')
const addTask = newTask => {
setTasks([...tasks,newTask])
}
return ( return (
<> <>
{/* Добавьте тестовый контент для проверки */} {/* Добавьте тестовый контент для проверки */}
<h1>Hello, React!</h1> <h1>Hello, React!</h1>
<Counter /> <QueryClientProvider client={createQueryClient}>
<PostAddForm />
</QueryClientProvider>
</> </>
) )
} }
-15
View File
@@ -1,15 +0,0 @@
.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;
}