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 35 additions and 47 deletions
+33 -47
View File
@@ -1,58 +1,44 @@
import React from 'react'
import { useMutation, QueryClientProvider, QueryClient } from '@tanstack/react-query'
import PostAddForm from './components/PostAddForm'
class RandomUser extends React.Component {
constructor(props) {
super(props)
this.state = { user: {} }
/*
const mutation = useMutation({
mutationFn: newUser => {
fetch('https://jsonplaceholder.typicode.com/users', {
method: 'GET',
headers: {'Content-type':'application/json'},
body: JSON.stringify(newUser),
}).then(res => res.json())
}
componentDidMount() {
fetch('https://randomuser.me/api')
.then(responce => responce.json())
.then(json => this.setState({ user: json.results[0] }));
console.log('смонтирован')
}
componentDidUpdate(prevProps,prevState) {
console.log(this.state);
console.log('Компонент обнвлен')
}
componentWillUnmount() {
console.log('Компонент таймера размонтирован')
}
render() {
return <div>
{this.state.user &&
this.state.user.name &&
(
<>
<h2>{this.state.user.name.first} {this.state.user.name.last}</h2>
<img src={this.state.user.picture.medium} />
<button onClick={() => {
console.log('Загружаем ... ')
fetch('https://randomuser.me/api')
.then(responce => responce.json())
.then(json => this.setState({ user: json.results[0] }));
}}>Загрузить нового</button>
</>
)
})
*/
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)}
}
</div>
}
}
})
}
function App() {
const [showClock, setShowClock] = React.useState(true);
return (
<>
<h1>Домашнее задание: жизненый цикл</h1>
<button onClick={()=> setShowClock(!showClock)}>
{showClock ? 'Скрыть часы' : 'Показать часы' }
</button>
{showClock && <RandomUser />}
{/* Добавьте тестовый контент для проверки */}
<h1>Hello, React!</h1>
<QueryClientProvider client={createQueryClient}>
<PostAddForm />
</QueryClientProvider>
</>
)
}
+2
View File
@@ -4,5 +4,7 @@ import { createRoot } from 'react-dom/client'
import App from './App.jsx'
createRoot(document.getElementById('root')).render(
<StrictMode>
<App />
</StrictMode>
)