When using import React, { useState } from 'react'
in your components, this is how you can mock useState
with jest
.
This file contains 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
interface HOC<T> { | |
(Component: React.ComponentType<T>): (props: T) => JSX.Element | |
} | |
const reduceHOCs = <T>(...hocs: HOC<T>[]): HOC<T> => hocs | |
.reduce((reduced, next) => (c) => next(reduced(c))); | |
const applyHOCs = <T>(...hocs: HOC<T>[]) { | |
const reducedHoc = reduceHOCs(...hocs); |
This file contains 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, { useReducer } from 'react'; | |
import { BrowserHistory, Update, History } from 'history'; | |
import { Router } from 'react-router-dom'; | |
import { | |
Middleware, createSlice, | |
} from '@reduxjs/toolkit'; | |
type ReduxAction<T = any> = { | |
type: string, | |
payload?: T, |
A compile-time 4-Bit Virtual Machine implemented in TypeScript's type system. Capable of running a sample 'FizzBuzz' program.
Syntax emits zero JavaScript.
type RESULT = VM<
[
["push", N_1], // 1
["push", False], // 2
["peek", _], // 3
Тут перечислены не законы, последние слово всегда за здравым смыслом. Тут перечислены лишь направление, куда надо стремиться. Принципы, которые должны помочь, когда не знаешь, что выбрать.
- Пользователь. Если что-то сильно мешает UX или есть критическая ошибка, то в первую очередь мы спасаем пользователей. Для этого иногда надо взять ответственность на себя, переубедить толпу, написать плохой код.
Amplifr’s rules for landing pages created by outsource.
This file contains 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
/** | |
* react-select + allOption | |
* | |
* author: [email protected], @alex_escalante | |
* | |
* Gives users of the fine component react-select the ability to select | |
* all options with a single click. | |
* | |
* We're basically wrapping react-select but using a special option, | |
* the "allOption". This option is exclusive of any other option |
This file contains 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
const jsdom = require("jsdom"); | |
const { JSDOM } = jsdom; | |
const dom = new JSDOM('<!DOCTYPE html><html><head></head><body></body></html>'); | |
global.window = dom.window; | |
global.document = dom.window.document; | |
// Simulate window resize event | |
const resizeEvent = document.createEvent('Event'); |
This file contains 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
function isPromise(object){ | |
if(Promise && Promise.resolve){ | |
return Promise.resolve(object) == object; | |
}else{ | |
throw "Promise not supported in your environment" | |
} | |
} | |
var i = 1; | |
var p = new Promise(function(resolve,reject){ |
NewerOlder