Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 23db798577 | |||
| c99a045400 |
Generated
-27
@@ -8,7 +8,6 @@
|
|||||||
"name": "store-client",
|
"name": "store-client",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tanstack/react-query": "^5.100.14",
|
|
||||||
"react": "^19.1.0",
|
"react": "^19.1.0",
|
||||||
"react-dom": "^19.1.0"
|
"react-dom": "^19.1.0"
|
||||||
},
|
},
|
||||||
@@ -1305,32 +1304,6 @@
|
|||||||
"win32"
|
"win32"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"node_modules/@tanstack/query-core": {
|
|
||||||
"version": "5.100.14",
|
|
||||||
"resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.100.14.tgz",
|
|
||||||
"integrity": "sha512-5X41dGpxgeaHISCRW2oYwcSycZeULZzAunaudXT9ov1KOTj9xwt0CH6hbwqP1/z74ZWF7rYFnDpyYH07XFcZew==",
|
|
||||||
"license": "MIT",
|
|
||||||
"funding": {
|
|
||||||
"type": "github",
|
|
||||||
"url": "https://github.com/sponsors/tannerlinsley"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@tanstack/react-query": {
|
|
||||||
"version": "5.100.14",
|
|
||||||
"resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-5.100.14.tgz",
|
|
||||||
"integrity": "sha512-oOr6aRdSFEwWhzxEkD/9ZcItM3+LjBSkeVmadWKwUssAHTsqd/7bOjWrX4AbvEkoEhgAxzN0Xk6H/aYzXiYBAw==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"@tanstack/query-core": "5.100.14"
|
|
||||||
},
|
|
||||||
"funding": {
|
|
||||||
"type": "github",
|
|
||||||
"url": "https://github.com/sponsors/tannerlinsley"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"react": "^18 || ^19"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@types/babel__core": {
|
"node_modules/@types/babel__core": {
|
||||||
"version": "7.20.5",
|
"version": "7.20.5",
|
||||||
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz",
|
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz",
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tanstack/react-query": "^5.100.14",
|
|
||||||
"react": "^19.1.0",
|
"react": "^19.1.0",
|
||||||
"react-dom": "^19.1.0"
|
"react-dom": "^19.1.0"
|
||||||
},
|
},
|
||||||
|
|||||||
+35
-78
@@ -1,93 +1,50 @@
|
|||||||
import React, {useState, useEffect, useRef } from 'react'
|
import { useState, useReducer } from 'react'
|
||||||
//import { useQuery } from '@tanstack/react-query'
|
|
||||||
|
|
||||||
function useWindowWidth() {
|
function counterReducer(state, action) {
|
||||||
const [width,setWidth] = useState(window.innerWidth)
|
switch (action.type) {
|
||||||
|
case 'increment':
|
||||||
useEffect(() => {
|
return state + 1
|
||||||
const handleResize = () => setWidth(window.innerWidth);
|
case 'decrement':
|
||||||
window.addEventListener('resize',handleResize);
|
return state - 1
|
||||||
return () => window.removeEventListener('resize',handleResize);
|
case 'reset':
|
||||||
},[])
|
return 0
|
||||||
|
case 'set_value':
|
||||||
return width
|
return action.value
|
||||||
|
default:
|
||||||
|
return state
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function useLocalStorage(key, initValue) {
|
function Counter() {
|
||||||
const [value, setValue] = useState(()=>{
|
const [count, dispatch] = useReducer(counterReducer,0);
|
||||||
const stored = localStorage.getItem(key);
|
|
||||||
return stored !== null ? JSON.parse(stored) : initValue
|
|
||||||
})
|
|
||||||
|
|
||||||
useEffect(() => {
|
return (
|
||||||
localStorage.setItem(key, JSON.stringify(value))
|
<div>
|
||||||
},[key, value])
|
<span>Счетчик: {count}</span>
|
||||||
|
<button onClick={()=> dispatch({type: 'increment'})}>+</button>
|
||||||
return [value,setValue]
|
<button onClick={()=> dispatch({type: 'decrement'})}>-</button>
|
||||||
}
|
<button onClick={()=> dispatch({type: 'reset'})}>reset</button>
|
||||||
/*
|
<button onClick={()=> dispatch({type: 'set_value', value: 5})}>set 5</button>
|
||||||
function useUserData(userId) {
|
</div>
|
||||||
return useQuery(
|
|
||||||
['user',userId],
|
|
||||||
() => fetch(`/api/user/${userId}`).then(res => res.json()),
|
|
||||||
{refetchOnWindowFocus: false}
|
|
||||||
)
|
)
|
||||||
}*/
|
|
||||||
|
|
||||||
function useInput(initValue, validate) {
|
|
||||||
const [value, setValue] = useState(initValue);
|
|
||||||
const [error, setError] = useState(null);
|
|
||||||
|
|
||||||
const onChange = e => {
|
|
||||||
const newValue = e.target.value
|
|
||||||
setValue(newValue)
|
|
||||||
if (validate) {
|
|
||||||
const validationResult = validate(newValue)
|
|
||||||
setError(validationResult)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { value, error, onChange }
|
|
||||||
}
|
|
||||||
|
|
||||||
function useInterval(callback, delay) {
|
|
||||||
const savedCallback = useRef()
|
|
||||||
|
|
||||||
useEffect(()=>{
|
|
||||||
savedCallback.current = callback
|
|
||||||
},[callback]);
|
|
||||||
|
|
||||||
useEffect(()=>{
|
|
||||||
if (delay == null) return
|
|
||||||
const id = setInterval(()=>{
|
|
||||||
savedCallback.current()
|
|
||||||
},delay);
|
|
||||||
return () => clearInterval(id);
|
|
||||||
},[delay])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const width = useWindowWidth();
|
const [tasks, setTasks] = useState([])
|
||||||
const [theme, setTheme] = useLocalStorage('theme','light');
|
const [filter, setFilter] = useState('all')
|
||||||
|
const [sortBy,setSortBy] = useState('date')
|
||||||
|
|
||||||
|
const addTask = newTask => {
|
||||||
|
setTasks([...tasks,newTask])
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const username = useInput(
|
|
||||||
'',
|
|
||||||
value => value.length < 3 ? 'минимум 3 символа' : null
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1>Hello, React!{width}</h1>
|
{/* Добавьте тестовый контент для проверки */}
|
||||||
<button onClick={()=>{
|
<h1>Hello, React!</h1>
|
||||||
setTheme(theme === 'light' ? 'dark' : 'light')
|
<Counter />
|
||||||
}}>
|
|
||||||
Сменить тему
|
|
||||||
</button>
|
|
||||||
<p><input type="text"
|
|
||||||
value={username.value}
|
|
||||||
onChange={username.onChange} />
|
|
||||||
{ username.error ? username.error : '' }
|
|
||||||
</p>
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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