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

React Classes-Component vs Functional-Component

Компоненты собственно бывают двух типов

Для начала возьмем компонент написанный на классе:

class SmartComponent extends Componennt {
  static defaultProps = {
    page: 1,
const future = executor => ({
chain(fn) {
return future((resolve, reject) =>
this.fork(
value => fn(value).fork(resolve),
error => reject(error),
)
)
},
map(fn) {

Модификация компонентов

С использованием bem-react/classname

Для визуального офомрления компонентов сейчас используем css-классы а так же бэм-модификаторы, которые строим в рантайме на каждый рендер компонента:

const cnButton = cn('Button')

const Button = ({ size, view, children }) => {
type LoaderProps<T> = {
fetching: boolean
data: T
}
const Loader: FC<LoaderProps> = ({ fetching, data, children }) => (
if (fetching) {
return <div>Loading...</div>
}
return children(data)
const createCache = () => {
const cacheMap = new Map()
return {
remember(key, setter) {
if (this.has(key)) {
return this.get(key)
}
const value = setter.call(null)
this.set(key, value)
return value
withBemMod<P, T>(blockName: string, mod: NoStrictEntityMods, cb?: ModBody<P>): (WrappedComponent: EnhancedComponentType<{}, {}, T>) => (props: P) => JSX.Element;
type EnhancedComponentType<T = {}, S = any, V = any> =
& React.ComponentType<T>
& Nominal<V>;
type GetKey<T> = T extends EnhancedComponentType<any, any, infer V> ? V : never;
type GetProps<T> = T extends React.ComponentType<infer V> ? V : never;
export function composeM<
SELECT CONCAT('ALTER TABLE `', t.`TABLE_SCHEMA`, '`.`', t.`TABLE_NAME`, '` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;') as sqlcode
FROM `information_schema`.`TABLES` t
WHERE 1
AND t.`TABLE_SCHEMA` = 'db_name'
ORDER BY 1
@yarastqt
yarastqt / easing.js
Last active September 27, 2017 10:28
const easing = {
easeInCubic(t) {
return t ** 3
},
easeOutCubic(t) {
return (--t) * t ** 2 + 1
},
easeInOutCubic(t) {