Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 10e56d8aaa |
-13
@@ -5,19 +5,6 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Vite + React</title>
|
<title>Vite + React</title>
|
||||||
<style>
|
|
||||||
* {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
box-sizing: border-box;
|
|
||||||
|
|
||||||
font-family: Arial, Helvetica, sans-serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
background-color: #ecfeff;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
|||||||
Generated
-11
@@ -20,7 +20,6 @@
|
|||||||
"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",
|
||||||
"react-icons": "^5.6.0",
|
|
||||||
"vite": "^6.3.5"
|
"vite": "^6.3.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -2462,16 +2461,6 @@
|
|||||||
"react": "^19.1.0"
|
"react": "^19.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/react-icons": {
|
|
||||||
"version": "5.6.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/react-icons/-/react-icons-5.6.0.tgz",
|
|
||||||
"integrity": "sha512-RH93p5ki6LfOiIt0UtDyNg/cee+HLVR6cHHtW3wALfo+eOHTp8RnU2kRkI6E+H19zMIs03DyxUG/GfZMOGvmiA==",
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"peerDependencies": {
|
|
||||||
"react": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/react-refresh": {
|
"node_modules/react-refresh": {
|
||||||
"version": "0.17.0",
|
"version": "0.17.0",
|
||||||
"resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.17.0.tgz",
|
"resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.17.0.tgz",
|
||||||
|
|||||||
+1
-2
@@ -4,7 +4,7 @@
|
|||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
"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",
|
||||||
"react-icons": "^5.6.0",
|
|
||||||
"vite": "^6.3.5"
|
"vite": "^6.3.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+70
-60
@@ -1,72 +1,82 @@
|
|||||||
import styles from './App.module.css'
|
import memo, { useMemo, useCallback, useState } from 'react'
|
||||||
import SneakersImage from './assets/images/sneakers-image.jpg'
|
|
||||||
import { FaRegUser } from 'react-icons/fa'
|
|
||||||
|
|
||||||
function handleClick(i) {
|
function MyComponent() {
|
||||||
console.log(i);
|
const [count, setCount] = useState(0);
|
||||||
}
|
const [name, setName] = useState('John');
|
||||||
|
|
||||||
function Header() {
|
const greeting = useMemo(() => `Hello, ${name}!`,[name]);
|
||||||
const handleChange = event => {
|
|
||||||
const newValue = event.target.value;
|
|
||||||
console.log(`Новое значение ${newValue}`);
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<header className={styles.header}>
|
<>
|
||||||
<div>
|
<h2>{greeting}</h2>
|
||||||
<h2>Store</h2>
|
<button onClick={()=>setName('Alex')}>New name</button>
|
||||||
<input type='text ' placeholder='Search...' onChange={handleChange} />
|
</>
|
||||||
</div>
|
)
|
||||||
<div>
|
|
||||||
<FaRegUser size={24} color='#3258e3' />
|
|
||||||
<button>Profile</button>
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function Product() {
|
function MyComponent2() {
|
||||||
const handlerMouseEnter = event => {
|
const [data,setData] = useState([{theme:'light'}])
|
||||||
const img = event.target;
|
const userPreferences = useMemo(()=>({theme: 'dark', language: 'en'}),[]);
|
||||||
img.style.border = '5px solid yellow';
|
|
||||||
}
|
const processData = useMemo(()=>{
|
||||||
const handlerMouseOut = event => {
|
return data.map(item => ({ ...item,theme: userPreferences.theme }))
|
||||||
const img = event.target;
|
},[data, userPreferences]);
|
||||||
img.style.border = '';
|
console.log(processData);
|
||||||
console.log(event);
|
return (
|
||||||
}
|
<>
|
||||||
return (
|
<h2 className={data.theme}>2</h2>
|
||||||
<div className={styles.product}>
|
<button onClick={()=>setData(data)}>set new theme</button>
|
||||||
<img src={SneakersImage} alt='' onMouseEnter={handlerMouseEnter} onMouseOut={handlerMouseOut} />
|
</>
|
||||||
<div className={styles.content}>
|
)
|
||||||
<div className={styles.title}>
|
}
|
||||||
<h4>Sneakers Red & White 2025</h4>
|
|
||||||
<button onClick={() => handleClick(0)} onMouseEnter={handlerMouseEnter} onMouseOut={handlerMouseOut}>+</button>
|
function MyComponent3() {
|
||||||
</div>
|
const sum = useMemo(()=> a+b,[a,b]);//Бессмысленное применение и вредное
|
||||||
<p className={styles.description}>NIKE</p>
|
|
||||||
<p className={styles.price}>$38.00</p>
|
//Применение оправдано
|
||||||
</div>
|
const complexResult = useMemo(()=>{
|
||||||
</div>
|
return heavyMethOperations(largeDataSet);
|
||||||
)
|
},[largeDataSet])
|
||||||
|
}
|
||||||
|
|
||||||
|
function ParentComponent({ items }) {
|
||||||
|
const [filter, setFilter] = useState('');
|
||||||
|
|
||||||
|
const listProps = useMemo(()=>({
|
||||||
|
items: items.filter(item => item.name.includes(filter)),
|
||||||
|
onItemClick: id => console.log('Clicked',id),
|
||||||
|
theme: 'dark'
|
||||||
|
}),[items,filter]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Memoized {...listProps} />
|
||||||
|
<button onClick={()=>setFilter('Bob')}>Click</button>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Memoized(props) {
|
||||||
|
console.log(props);
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h3 className={props.theme}>Memoized</h3>
|
||||||
|
{props.items.map((item) => (
|
||||||
|
<>
|
||||||
|
<li>
|
||||||
|
{item.name}
|
||||||
|
</li>
|
||||||
|
</>))}
|
||||||
|
</>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={styles.container}>
|
{/* Добавьте тестовый контент для проверки */}
|
||||||
<Header />
|
<h1>Hello, React!</h1>
|
||||||
<ul className={styles.list}>
|
<ParentComponent items={[{name:'Alex'},{name:'Bob'}]} />
|
||||||
<li>
|
|
||||||
<Product />
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<Product />
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<Product />
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,123 +0,0 @@
|
|||||||
@use './assets/styles/variables' as *;
|
|
||||||
|
|
||||||
.header {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
padding: 20px;
|
|
||||||
background-color: white;
|
|
||||||
|
|
||||||
border-bottom-left-radius: 10px;
|
|
||||||
border-bottom-right-radius: 10px;
|
|
||||||
|
|
||||||
div {
|
|
||||||
&:first-child {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 20px;
|
|
||||||
|
|
||||||
h2 {
|
|
||||||
color: $primary-color;
|
|
||||||
}
|
|
||||||
|
|
||||||
input {
|
|
||||||
border-radius: 5px;
|
|
||||||
outline: none;
|
|
||||||
font-size: 16px;
|
|
||||||
border: 1px solid gainsboro;
|
|
||||||
padding: 5px 10px;
|
|
||||||
|
|
||||||
&:focus {
|
|
||||||
border: 1px solid $primary-color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&:last-child {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 10px;
|
|
||||||
|
|
||||||
button {
|
|
||||||
outline: 0;
|
|
||||||
border: 0;
|
|
||||||
border-radius: 5px;
|
|
||||||
padding: 5px 15px;
|
|
||||||
font-size: 16px;
|
|
||||||
background-color: $primary-color;
|
|
||||||
color: $white-color;
|
|
||||||
font-weight: 600;
|
|
||||||
cursor: pointer;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: $seconday-color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.container {
|
|
||||||
max-width: 1220px;
|
|
||||||
margin: 0 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.list {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
border-radius: 10px;
|
|
||||||
margin-top: 100px; /* временно */
|
|
||||||
padding: 20px;
|
|
||||||
background-color: white;
|
|
||||||
list-style: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.product {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
width: 350px;
|
|
||||||
gap: 20px;
|
|
||||||
border-radius: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.content {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.title {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
h4 {
|
|
||||||
font-size: 18px;
|
|
||||||
}
|
|
||||||
|
|
||||||
button {
|
|
||||||
background-color: black;
|
|
||||||
color: white;
|
|
||||||
border: 0;
|
|
||||||
border-radius: 50%;
|
|
||||||
outline: 0;
|
|
||||||
|
|
||||||
font-size: 20px;
|
|
||||||
padding: 5px 10px;
|
|
||||||
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
img {
|
|
||||||
border-radius: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.description {
|
|
||||||
color: gray;
|
|
||||||
}
|
|
||||||
|
|
||||||
.price {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 23 KiB |
@@ -1,5 +0,0 @@
|
|||||||
$white-color: white;
|
|
||||||
$black-color: black;
|
|
||||||
|
|
||||||
$primary-color: #3258e3;
|
|
||||||
$seconday-color: #4432e3;
|
|
||||||
+1
-2
@@ -1,9 +1,8 @@
|
|||||||
import { StrictMode } from 'react'
|
import { StrictMode } from 'react'
|
||||||
import { createRoot } from 'react-dom/client'
|
import { createRoot } from 'react-dom/client'
|
||||||
|
// удаляем import './index.css'
|
||||||
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