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:7f29019605a5dec8d0f746f82e50b598
Created June 11, 2025 13:56
заготовка простейшего примера на редакс
import { createStore } from 'redux';
import { Provider, useSelector, useDispatch } from 'react-redux';
// npm install redux react-redux
// редьюсер для счетчика
const counterReducer = (state = { count: 0 }, action) => {
switch (action.type) {
case 'INCREMENT':
return { count: state.count + 1 };
case 'DECREMENT':
@sunmeat
sunmeat / different files.jsx
Created June 11, 2025 12:40
reactagram v.0.1 - useParams, useNavigate, useLocation, запросы
App.jsx:
import {
BrowserRouter,
Routes,
Route,
NavLink,
Link,
Outlet,
Navigate,

App.jsx

import logo from './assets/logo.jpg';
import './App.css'
import ContactInfo from "./ContactInfo.jsx";
import Title from "./Title.jsx";

function App() {
 return (
@sunmeat
sunmeat / App.jsx
Created June 10, 2025 12:33
error 404 example
...
function NotFound() {
return (
<div className="page-content">
<h1 className="page-title">404 - Страница не найдена</h1>
<p className="about-text">Извините, запрашиваемая страница не существует.</p>
<div className="link-group">
<Link to="/" className="page-link">Вернуться в ленту</Link>
<Link to="/profile" className="page-link">Профиль</Link>
@sunmeat
sunmeat / different files.jsx
Created June 10, 2025 11:46
react router outlet example
App.jsx:
import {BrowserRouter, Routes, Route, NavLink, Link, Outlet, Navigate} from 'react-router';
import './App.css';
import {useState} from "react";
function Home() {
return (
<div className="page-content">
<h1 className="page-title home-title">Лента</h1>
@sunmeat
sunmeat / different files.jsx
Last active July 2, 2025 16:42
link и navlink
App.jsx:
import {BrowserRouter, Routes, Route, NavLink, Link} from 'react-router';
import './App.css';
function Home() {
return (
<div className="page-content">
<h1 className="page-title home-title">Лента</h1>
<div className="post">
@sunmeat
sunmeat / App.jsx
Last active June 10, 2025 10:17
простейший пример на навигацию
import { BrowserRouter, Routes, Route } from 'react-router';
// npm install react-router
// ранее было npm install react-router-dom, впрочем этот пакет тоже пока рабочий
// https://www.npmjs.com/package/react-router
// компонент домашней страницы
function Home() {
return <h1>Привет, это главная страница!</h1>;
}
@sunmeat
sunmeat / different files.jsx
Created June 9, 2025 08:09
интернет магазин на классовых компонентах
App.jsx:
import React, {Component} from 'react';
import {QueryClient, QueryClientProvider, useQuery, useMutation, useQueryClient} from '@tanstack/react-query'; // npm install @tanstack/react-query
import Dexie from 'dexie'; // npm install dexie
import './App.css';
const db = new Dexie('CartDatabase');
db.version(1).stores({
cart: 'id, title, price, image, quantity',
@sunmeat
sunmeat / App.jsx
Created June 9, 2025 07:24
привязка обработчика события в классовом компоненте
import React, {useState, useEffect} from 'react';
import './App.css';
const getTimeWithMicroseconds = () => {
const now = new Date();
const micros = Math.floor(performance.now() * 1000) % 1000000;
return `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}:${now.getSeconds().toString().padStart(2, '0')}.${micros.toString().padStart(6, '0')}`;
};
const FunctionalButton = ({width, height, color, text}) => {
@sunmeat
sunmeat / App.jsx
Last active June 9, 2025 07:20
сравнение жизненных циклов
import React, {useState, useEffect} from 'react';
import './App.css';
// время с микросекундами
const getTimeWithMicroseconds = () => {
const now = new Date();
const micros = Math.floor(performance.now() * 1000) % 1000000;
return `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}:${now.getSeconds().toString().padStart(2, '0')}.${micros.toString().padStart(6, '0')}`;
};