This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect, useRef } from 'react'; | |
import './App.css'; | |
function App() { | |
const [products, setProducts] = useState([]); | |
const [page, setPage] = useState(1); | |
const [isLoading, setIsLoading] = useState(false); | |
const observerRef = useRef(); | |
const loadMore = async () => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect } from 'react'; | |
import './App.css'; | |
function App() { | |
const [orders, setOrders] = useState([]); | |
useEffect(() => { | |
const ws = new WebSocket('ws://your-server.com/orders'); | |
ws.onmessage = (event) => { | |
const newOrder = JSON.parse(event.data); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from 'react'; | |
import './App.css'; | |
function App() { | |
const [file, setFile] = useState(null); | |
const [preview, setPreview] = useState(null); | |
const [message, setMessage] = useState(''); | |
const handleFileChange = (e) => { | |
const selectedFile = e.target.files[0]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql table structure: | |
USE 4115733_words; // your DB name here | |
CREATE TABLE cart ( | |
id INT AUTO_INCREMENT PRIMARY KEY, | |
product_id INT NOT NULL, | |
title VARCHAR(255) NOT NULL, | |
price DECIMAL(10, 2) NOT NULL, | |
image VARCHAR(255) NOT NULL | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect } from 'react'; | |
import './App.css'; | |
function App() { | |
const [products, setProducts] = useState([]); | |
const [isLoading, setIsLoading] = useState(false); | |
const [error, setError] = useState(null); | |
useEffect(() => { | |
const fetchProducts = async () => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.env файл в корне проекта: | |
# .env | |
VITE_API_URL=https://jsonplaceholder.typicode.com | |
переменные окружения в Vite обязаны начинаться с VITE_, иначе они не будут доступны в коде. | |
=================================================================================================== | |
в React-коде: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react'; | |
const BlockingExample = () => { | |
const [isBlocked, setIsBlocked] = useState(false); | |
const [inputValue, setInputValue] = useState(''); | |
const [checked, setChecked] = useState(false); | |
const blockPageForever = () => { | |
setIsBlocked(true); | |
console.log('СТРАНИЦА БУДЕТ ЗАМОРОЖЕНА НАВСЕГДА...'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {useState, useEffect, useRef} from 'react'; | |
const styles = { | |
container: { | |
fontFamily: 'Arial, sans-serif', | |
backgroundColor: '#121212', | |
color: '#fff', | |
textAlign: 'center', | |
padding: '2rem', | |
minHeight: '100vh', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {useState} from 'react'; | |
const styles = { | |
container: { | |
fontFamily: 'Arial, sans-serif', | |
backgroundColor: '#121212', | |
color: '#fff', | |
textAlign: 'center', | |
padding: '2rem', | |
minHeight: '100vh', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {useState} from 'react'; | |
// CSS-in-JS стили | |
const styles = { | |
body: { | |
fontFamily: "'Courier New', monospace", | |
backgroundColor: '#121212', | |
color: '#ffffff', | |
padding: '2rem', | |
margin: 0, |