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 36 additions and 34 deletions
+34 -34
View File
@@ -1,44 +1,44 @@
import React from 'react' import { useMutation, QueryClientProvider, QueryClient } from '@tanstack/react-query'
import PostAddForm from './components/PostAddForm'
class Clock extends React.Component { /*
constructor(props) { const mutation = useMutation({
super(props) mutationFn: newUser => {
this.state = { time: new Date().toLocaleTimeString() } fetch('https://jsonplaceholder.typicode.com/users', {
} method: 'GET',
headers: {'Content-type':'application/json'},
componentDidMount() { body: JSON.stringify(newUser),
this.timerId = setInterval(()=>{ }).then(res => res.json())
this.setState({ time: new Date().toLocaleTimeString() })
}, 1000);
console.log('Таймер смонтирован')
}
componentDidUpdate(prevProps,prevState) {
console.log('Компонент обнвлен')
}
componentWillUnmount() {
clearInterval(this.timerId)
console.log('Компонент таймера размонтирован')
}
render() {
return <div>
<h2>Текущее время: {this.state.time}</h2>
</div>
} }
})
*/
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 App() { function App() {
const [showClock, setShowClock] = React.useState(true);
return ( return (
<> <>
<h1>Жизненный цикл компонента часов</h1> {/* Добавьте тестовый контент для проверки */}
<button onClick={()=> setShowClock(!showClock)}> <h1>Hello, React!</h1>
{showClock ? 'Скрыть часы' : 'Показать часы' } <QueryClientProvider client={createQueryClient}>
</button> <PostAddForm />
{showClock && <Clock />} </QueryClientProvider>
</> </>
) )
} }
+2
View File
@@ -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>
) )