Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b70fa47bbc | |||
| bd35029fc1 | |||
| 92dc5df96b | |||
| 3d34262203 | |||
| 1bc2e883a1 | |||
| 8a8a17f44d | |||
| 8f46470a26 |
Generated
+1256
-9
File diff suppressed because it is too large
Load Diff
@@ -10,6 +10,7 @@
|
|||||||
"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"
|
||||||
},
|
},
|
||||||
@@ -22,6 +23,8 @@
|
|||||||
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-34
@@ -1,44 +1,29 @@
|
|||||||
import { useMutation, QueryClientProvider, QueryClient } from '@tanstack/react-query'
|
import styles from './styles/App.module.scss'
|
||||||
import PostAddForm from './components/PostAddForm'
|
import React, { useState, useCallback } from 'react'
|
||||||
|
|
||||||
/*
|
function CounterButton({label, onClick}) {
|
||||||
const mutation = useMutation({
|
return (
|
||||||
mutationFn: newUser => {
|
<button onClick={onClick} className={styles.counter_button}>{label}</button>
|
||||||
fetch('https://jsonplaceholder.typicode.com/users', {
|
)
|
||||||
method: 'GET',
|
|
||||||
headers: {'Content-type':'application/json'},
|
|
||||||
body: JSON.stringify(newUser),
|
|
||||||
}).then(res => res.json())
|
|
||||||
}
|
}
|
||||||
})
|
function CounterDisplay({value}) {
|
||||||
*/
|
return (<div className={styles.counter_display}>
|
||||||
|
Значение счетчика: <b>{value}</b>
|
||||||
const createQueryClient = () => {
|
</div>)
|
||||||
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 App() {
|
function App() {
|
||||||
|
const [counter,setCounter] = useState(0);
|
||||||
|
|
||||||
|
const increment = () => setCounter(prev => prev + 1);
|
||||||
|
const decrement = () => setCounter(prev => prev - 1);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Добавьте тестовый контент для проверки */}
|
<h2>Практика по созданию счетчика с колбэками</h2>
|
||||||
<h1>Hello, React!</h1>
|
<CounterButton label="Увеличить" onClick={increment} />
|
||||||
<QueryClientProvider client={createQueryClient}>
|
<CounterButton label="уменьшить" onClick={decrement} />
|
||||||
<PostAddForm />
|
<CounterDisplay value={counter} />
|
||||||
</QueryClientProvider>
|
|
||||||
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user