Skip to content

Instantly share code, notes, and snippets.

View yarastqt's full-sized avatar
⚛️
Hello from the dark side

Eugene Tropin yarastqt

⚛️
Hello from the dark side
View GitHub Profile
import { useState } from 'react'
import { useUniqId } from '../../libs/useUniqId'
export function useSelectState(props: any) {
const { children } = props
const [isOpened, setOpened] = useState(false)
const [selected, setSelected] = useState<{ option: any; value: any }>({} as any)
const [focusedIndex, setFocusedIndex] = useState(-1)
const [selectedIndex, setSelectedIndex] = useState(-1)

Про модификаторы

  1. Написать про то, что такое API компонента и на самом деле модификаторы являются частью компонента при проектировании
  2. Написать про createClassNameModifier/withBemMod/dedup cn — что это на самом деле все не нужно
import { useState, useEffect } from "react";
export function useIsClient() {
const [isClient, setClient] = useState(false);
useEffect(() => {
setClient(true);
}, []);
return isClient;
export const locales = [
{ label: 'Auto', value: '' },
// Tier 1
{ label: 'French (France)', value: 'fr-FR' },
{ label: 'French (Canada)', value: 'fr-CA' },
{ label: 'German (Germany)', value: 'de-DE' },
{ label: 'English (Great Britain)', value: 'en-GB' },
{ label: 'English (United States)', value: 'en-US' },
{ label: 'Japanese (Japan)', value: 'ja-JP' },
// // Tier 2
/* eslint-disable no-console */
import { useRef, useEffect } from 'react';
export function useWhyDidYouUpdate(name: string, props: any) {
// Get a mutable ref object where we can store props ...
// ... for comparison next time this hook runs.
const previousProps = useRef<any>();
useEffect(() => {
if (previousProps.current) {
export default function deprecated(props, instead, component) {
if (typeof window !== 'undefined' && window.console && window.console.error) {
window.console.error(
`Warning: ${props} is deprecated at [ ${component} ], ` +
`use [ ${instead} ] instead of it.`
);
}
}
const useCopyToClipboard = (text) => {
const copyToClipboard = (str) => {
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
const selected =
document.getSelection().rangeCount > 0
import {
EffectCallback,
DependencyList,
useLayoutEffect,
useState,
useEffect,
useMemo,
} from 'react'
// lib/canUseDOM
.Button {
border-radius: 4px;
background-color: #ccc;
color: #000;
font-size: 15px;
font-family: Arial, sans-serif;
}