Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 43aeb40b20 |
+31
-32
@@ -1,34 +1,33 @@
|
|||||||
import React, { useMemo, useCallback, useState } from 'react'
|
import { useMutation, QueryClientProvider, QueryClient } from '@tanstack/react-query'
|
||||||
|
import PostAddForm from './components/PostAddForm'
|
||||||
|
|
||||||
const TodoItem = React.memo(({ item, onToggle, onDelete }) => {
|
/*
|
||||||
console.log(`rendred ${item.id}`);
|
const mutation = useMutation({
|
||||||
return <li>
|
mutationFn: newUser => {
|
||||||
{item.name}
|
fetch('https://jsonplaceholder.typicode.com/users', {
|
||||||
<button onClick={() => onToggle(item.id)}>Done</button>
|
method: 'GET',
|
||||||
<button onClick={() => onDelete(item.id)}>remove</button>
|
headers: {'Content-type':'application/json'},
|
||||||
</li>
|
body: JSON.stringify(newUser),
|
||||||
|
}).then(res => res.json())
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
*/
|
||||||
|
|
||||||
function ItemList({ items }) {
|
const createQueryClient = () => {
|
||||||
|
new QueryClient({
|
||||||
const handleToggle = useCallback(id => {
|
defaultOptions: {
|
||||||
items.done = true;
|
queries: {
|
||||||
console.log(`Item ${id} done`)
|
staleTime: 5 * 60*1000,
|
||||||
console.log(id)
|
retry: 1,
|
||||||
},[]);
|
gcTime: 10*60*1000,
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
const handleDelete = useCallback(id => {
|
},
|
||||||
items.pop(id);
|
mutations: {
|
||||||
},[]);
|
retry:0,
|
||||||
return (
|
onError: error => {console.error('Mutation error:',error.message)}
|
||||||
<>
|
}
|
||||||
<h3>List items</h3>
|
}
|
||||||
{items.map(item => (
|
})
|
||||||
<TodoItem key={item.id} item={item}
|
|
||||||
onToggle={handleToggle} onDelete={handleDelete} />
|
|
||||||
))}
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
@@ -36,10 +35,10 @@ function App() {
|
|||||||
<>
|
<>
|
||||||
{/* Добавьте тестовый контент для проверки */}
|
{/* Добавьте тестовый контент для проверки */}
|
||||||
<h1>Hello, React!</h1>
|
<h1>Hello, React!</h1>
|
||||||
<ItemList items={[
|
<QueryClientProvider client={createQueryClient}>
|
||||||
{id:1,name:'Первый',done:false},
|
<PostAddForm />
|
||||||
{id:2,name:'Второй',done:false}
|
</QueryClientProvider>
|
||||||
]} />
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,5 +4,7 @@ import { createRoot } from 'react-dom/client'
|
|||||||
import App from './App.jsx'
|
import App from './App.jsx'
|
||||||
|
|
||||||
createRoot(document.getElementById('root')).render(
|
createRoot(document.getElementById('root')).render(
|
||||||
|
<StrictMode>
|
||||||
<App />
|
<App />
|
||||||
|
</StrictMode>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user