Skip to content

Instantly share code, notes, and snippets.

@freeudv
freeudv / Prefetch hook
Last active December 13, 2019 06:48
Custom Hooks
// custom hook to prefetch components
const usePrefetch = (factory) => {
const [component, setComponent] = useState(null)
useEffect(() => {
factory()
const comp = lazy(factory)
setComponent(comp)
}, [factory])
@freeudv
freeudv / promises
Created April 15, 2018 18:35
promises
const makePromise = num => {
return new Promise((resolve, reject) => {
const delay = Math.floor(Math.random() * 3000);
console.log(num, delay);
setTimeout(() => {
if (delay > 2000) {
reject(num);
} else {
resolve(num);
import MyComponent from './MyComponent';
import { dataFetch, dataFetched } from '../actions';
const mapStateToProps = ({ data }) => ({
data
});
const fetchDataFromUrl = (dispatch) => async (url) => {
dispatch(dataFetch());
import styled, { css } from 'styled-components'
export const Container = styled.div`
max-width: 1200px;
margin: 0 auto;
padding: 0 8px;
`
export const Row = styled.div`
display: flex;
const fs = require('fs');
const postcss = require('postcss');
const autoprefixer = require('autoprefixer');
const postcssCustomProperties = require('postcss-custom-properties');
const postcssCalc = require('postcss-calc');
const csso = require('csso');
const source = fs.readFileSync('./source/main.css');
const processResult = postcss()
@freeudv
freeudv / webpack1
Created October 20, 2017 05:56
webpack.config.js
'use strict'
const webpack = require('webpack')
const path = require('path')
module.exports = {
entry: {
app: ['react-hot-loader/patch', path.resolve(__dirname, './src/index.js')]
},
@freeudv
freeudv / Adapter
Last active October 13, 2017 06:38
JS patterns
class ToggleButton {
static get adapter() {
return {
addClass: (element, className) => {},
removeClass: (element, className) => {},
hasClass: (element, className) => {},
setTextContent: (element, text) => {},
addEventHandler: (element, event, handler) => {},
removeEventHandler: (element, event, handler) => {}
};
{
"editor.fontFamily": "Fira Code",
"editor.fontSize": 14,
"editor.fontLigatures": true,
"editor.formatOnSave": true,
"editor.tabSize": 2,
"editor.letterSpacing": 0.5,
"editor.renderWhitespace": "all",
"editor.renderIndentGuides": true,
"editor.wordWrap": "on",
git branch – показать список локальных веток
git branch -r – показать список удаленных веток
git branch -a – показать список всех веток (локальных и удаленных)
git checkout <branch> / <commit> – переключиться на ветку / коммит
git checkout -b <branch> – создать новую ветку
git branch -D <branch> – удалить существующую ветку
git push origin :<branch> – удалить удаленную ветку на сервере
git fetch – взять изменения с сервера
git pull – взять изменения с сервера и смержить их с текущей локальной веткой
git pull origin – взять изменения с сервера и смержить их о всеми локальными ветками
@freeudv
freeudv / button.scss
Last active April 24, 2017 13:26 — forked from agragregra/button.sass
Button Sass Styles (Universal Starter)
.btn {
position: relative;
display: inline-block;
padding: 15px 45px;
font-size: 13px;
font-weight: 600;
letter-spacing: 3px;
text-decoration: none;
text-transform: uppercase;
text-align: center;