Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 23db798577 | |||
| c99a045400 |
+37
-31
@@ -1,44 +1,50 @@
|
|||||||
import { useMutation, QueryClientProvider, QueryClient } from '@tanstack/react-query'
|
import { useState, useReducer } from 'react'
|
||||||
import PostAddForm from './components/PostAddForm'
|
|
||||||
|
|
||||||
/*
|
function counterReducer(state, action) {
|
||||||
const mutation = useMutation({
|
switch (action.type) {
|
||||||
mutationFn: newUser => {
|
case 'increment':
|
||||||
fetch('https://jsonplaceholder.typicode.com/users', {
|
return state + 1
|
||||||
method: 'GET',
|
case 'decrement':
|
||||||
headers: {'Content-type':'application/json'},
|
return state - 1
|
||||||
body: JSON.stringify(newUser),
|
case 'reset':
|
||||||
}).then(res => res.json())
|
return 0
|
||||||
|
case 'set_value':
|
||||||
|
return action.value
|
||||||
|
default:
|
||||||
|
return state
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
const createQueryClient = () => {
|
function Counter() {
|
||||||
new QueryClient({
|
const [count, dispatch] = useReducer(counterReducer,0);
|
||||||
defaultOptions: {
|
|
||||||
queries: {
|
return (
|
||||||
staleTime: 5 * 60*1000,
|
<div>
|
||||||
retry: 1,
|
<span>Счетчик: {count}</span>
|
||||||
gcTime: 10*60*1000,
|
<button onClick={()=> dispatch({type: 'increment'})}>+</button>
|
||||||
refetchOnWindowFocus: false,
|
<button onClick={()=> dispatch({type: 'decrement'})}>-</button>
|
||||||
},
|
<button onClick={()=> dispatch({type: 'reset'})}>reset</button>
|
||||||
mutations: {
|
<button onClick={()=> dispatch({type: 'set_value', value: 5})}>set 5</button>
|
||||||
retry:0,
|
</div>
|
||||||
onError: error => {console.error('Mutation error:',error.message)}
|
)
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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>
|
||||||
<QueryClientProvider client={createQueryClient}>
|
<Counter />
|
||||||
<PostAddForm />
|
|
||||||
</QueryClientProvider>
|
|
||||||
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user