Skip to content

Instantly share code, notes, and snippets.

View sunmeat's full-sized avatar
🐈
MEOW

Oleksandr Zahoruiko sunmeat

🐈
MEOW
View GitHub Profile
@sunmeat
sunmeat / gist:b311394bbfad3542daf250628a0574ad
Created May 30, 2025 13:50
ленивая загрузка товаров
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 () => {
@sunmeat
sunmeat / gist:6c7cb721d2eb4db650aac2db5f87f947
Created May 30, 2025 13:49
черновик уведомления вебсокет
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);
@sunmeat
sunmeat / gist:356088fcdb6d8663cb5d0f915038b47c
Created May 30, 2025 13:48
черновик работа с файлами
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];
@sunmeat
sunmeat / different files.jsx
Last active June 3, 2025 08:43
react + php + mysql
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
);
@sunmeat
sunmeat / App.jsx
Created May 30, 2025 13:38
useEffect + isLoading (образец, не запускать :)
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 () => {
@sunmeat
sunmeat / different files
Created May 30, 2025 13:15
пример конфигурации VITE_API_URL
.env файл в корне проекта:
# .env
VITE_API_URL=https://jsonplaceholder.typicode.com
переменные окружения в Vite обязаны начинаться с VITE_, иначе они не будут доступны в коде.
===================================================================================================
в React-коде:
@sunmeat
sunmeat / App.jsx
Created May 30, 2025 12:46
пример блокировки страницы :)
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('СТРАНИЦА БУДЕТ ЗАМОРОЖЕНА НАВСЕГДА...');
@sunmeat
sunmeat / App.jsx
Created May 30, 2025 12:32
привязка запроса к ЖЦ компоненты
import React, {useState, useEffect, useRef} from 'react';
const styles = {
container: {
fontFamily: 'Arial, sans-serif',
backgroundColor: '#121212',
color: '#fff',
textAlign: 'center',
padding: '2rem',
minHeight: '100vh',
@sunmeat
sunmeat / App.jsx
Created May 30, 2025 12:17
получение файлов + демо POST метода fetch API REACT
import React, {useState} from 'react';
const styles = {
container: {
fontFamily: 'Arial, sans-serif',
backgroundColor: '#121212',
color: '#fff',
textAlign: 'center',
padding: '2rem',
minHeight: '100vh',
@sunmeat
sunmeat / App.jsx
Created May 30, 2025 12:05
Jokes API + fetch REACT
import React, {useState} from 'react';
// CSS-in-JS стили
const styles = {
body: {
fontFamily: "'Courier New', monospace",
backgroundColor: '#121212',
color: '#ffffff',
padding: '2rem',
margin: 0,