Skip to content

Instantly share code, notes, and snippets.

View mlshv's full-sized avatar

Misha mlshv

View GitHub Profile
@mlshv
mlshv / use-timeout.js
Created December 11, 2020 08:25
useTimeout
import { useState, useEffect } from 'react'
const removeKeyFromState = (key, setState) => {
setState(({ [key]: deletedKey, ...restKeys }) => ({ ...restKeys }))
}
const useTimeout = () => {
const [timeouts, setTimeouts] = useState({})
useEffect(() => {
@mlshv
mlshv / translit.js
Last active October 26, 2023 21:00
Двусторонний транслит (перевод с транслита на русский и наоборот)
// Чуть-чуть поменял код отсюда: https://javascript.ru/forum/misc/27347-nadezhnyjj-dvukhstoronnijj-translit.html#post168115
var transliterate = (
function() {
var rus = "щ ш ч ц ю я ё ж з ъ ы э а б в г д е з и й к л м н о п р с т у ф х ь".split(/ +/g);
var eng = "shh sh ch cz yu ya yo zh th `` y' e` a b v g d e z i j k l m n o p r s t u f h `".split(/ +/g);
return function(text, engToRus) {
for (var x = 0; x < rus.length; x++) {
text = text.split(engToRus ? eng[x] : rus[x]).join(engToRus ? rus[x] : eng[x]);
text = text.split(engToRus ? eng[x].toUpperCase() : rus[x].toUpperCase()).join(engToRus ? rus[x].toUpperCase() : eng[x].toUpperCase());
@mlshv
mlshv / Button.jsx
Last active September 24, 2019 10:49
sc override with classes
import React from 'react'
import styled from 'styled-components'
import Icon from 'components/Icon'
const ButtonWrap = styled.button`
padding: 8px 12px;
color: #fff;
background: #333;
`
@mlshv
mlshv / Article.js
Last active November 20, 2018 09:15
import React, { Component } from "react";
class Article extends Component {
constructor(props) {
super(props)
this.state = {
isOpen: props.defaultOpen,
idAd: props.idAd
}
@mlshv
mlshv / example.js
Created November 17, 2018 09:23
single variable example event
// in some react class component
handleChangeInput = (e) => {
this.setState({ [e.target.name]: e.target.value })
}
@mlshv
mlshv / example.js
Last active November 17, 2018 09:15
single variable example for-loop in generator
for (const a of actions) {
watchers.push(yield createWatcher(a))
}
@mlshv
mlshv / example.js
Last active March 1, 2019 09:12
single variable example exception
try {
return someUnsafeAction();
} catch (e) {
console.error(e);
return `Error: ${e.message}`;
}
@mlshv
mlshv / example.js
Last active March 1, 2019 09:10
single variable example iterator
const currentUser = users.find(u => u.id === currentUserId);
@mlshv
mlshv / Button.jsx
Created April 2, 2018 20:05
ITCFnd. Кнопка Delivery
import styled from 'styled-components';
const Button = styled.button`
padding: 12px 32px;
line-height: 1;
border: none;
border-radius: 34.5px;
opacity: .9;
color: #fff;
background-color: #a3d200;
@mlshv
mlshv / StoreCard.jsx
Created April 2, 2018 19:53
ITCFnd. Карточка магазина - компонент
import React from 'react';
import styled from 'styled-components';
const Link = styled.a`
display: block;
margin-bottom: 48px;
text-decoration: inherit;
color: inherit;
`;