Skip to content

Instantly share code, notes, and snippets.

View sseletskyy's full-sized avatar
🍊
FP mood

Sergiy Seletskyy sseletskyy

🍊
FP mood
View GitHub Profile
@sseletskyy
sseletskyy / custom-react-hooks.ts
Created May 29, 2020 12:40
Custom React Hooks
import { RefObject, useRef } from 'react';
// custom react hook to implement blur logic on click event
// function returns ref and callback
// ref should be set to anchor, e.g. <a ref={ref} ...></a>
// callback should be called without params in onClick handler,
// e.g. <a onClick={(e)=> { forceBlur(); ... } />
export function useForceBlur(): [RefObject<HTMLAnchorElement>, () => void] {
const ref = useRef<HTMLAnchorElement>(null);
const forceBlur = () => {
@sseletskyy
sseletskyy / machine.js
Created March 11, 2020 14:40
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'fetch',
initial: 'unverified',
context: {
smsBlockVisible: false,
verifyCodeButtonDisabled: true,
phoneNumberInputReadOnly: false,
sendCodeButtonVisible: true,
unlinkPhoneButtonVisible: false,
successMessage: 'undefined',

Sergiy Seletskyy

Speaker at conferences

  1. FOSS Sea 2013 - "Как использовать PaaS Heroku"
  2. ...
@sseletskyy
sseletskyy / memoize.js
Created August 22, 2018 19:29
Memoization example
function memoize(func) {
const map = new Map()
return function() {
const args = Array.prototype.slice.call(arguments)
const key = JSON.stringify(args)
if (! map.has(key)) map.set(key, func.apply(null, args))
return map.get(key)
}
}
@sseletskyy
sseletskyy / ReduxFormControl.test.js
Last active June 27, 2017 08:12
How to test a control in redux-form
/*
This is an example of a test for a Control Component inside of Redux Form
*/
import React from 'react';
import ComponentToBeTested from '../ComponentToBeTested';
import configureStore from 'redux-mock-store';
import { Provider } from 'react-redux';
import { mount } from 'enzyme';
import { reduxForm } from 'redux-form';
@sseletskyy
sseletskyy / Redux Reducer Template.js
Created December 30, 2016 11:49
Redux Reducer Template
import * as types from '../actions/actionTypes'
import initialState from './initialState'
export default function $NAME(state = initialState.$NAME, action) {
switch (action.type) {
case types.:
return state;
default:
return state;
}
@sseletskyy
sseletskyy / React Container Test.jsx
Created December 30, 2016 11:48
React Container Test
import React from 'react';
import expect from 'expect';
import {shallow, mount} from 'enzyme'
import {$NAME} from './$NAME'
describe('<$NAME />', ()=>{
function setup() {
let props = {
actions: { someAction: () => Promise.resolve() }
@sseletskyy
sseletskyy / react-class-component-template.js
Created December 20, 2016 14:58 — forked from jim-at-jibba/react-class-component-template.js
React Class Component Webstorm/PHPStorm File Template
import React, { PropTypes, Component } from 'react';
class $NAME extends Component {
render() {
return (
);
}
}
@sseletskyy
sseletskyy / react-stateless-component-template.js
Created December 20, 2016 14:56 — forked from jim-at-jibba/react-stateless-component-template.js
React Stateless Component Webstorm/PHPStorm File Template
import React, { PropTypes } from 'react';
const $NAME = (props) => {
return (
$END
);
}
$NAME.propTypes = {
// myProp: PropTypes.string.isRequired
@sseletskyy
sseletskyy / react-redux-container-template.js
Created December 20, 2016 14:53 — forked from jim-at-jibba/react-redux-container-template.js
React Redux Container Component Webstorm/PHPStorm File Template
import React, { PropTypes, Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
// Import actions here!!
class $NAME extends Component {
constructor(props, context) {
super(props, context);
}