Skip to content

Instantly share code, notes, and snippets.

View stephenway's full-sized avatar

Stephen Way stephenway

View GitHub Profile
import { useField } from 'formik'
import React from 'react'
import StringMask from 'string-mask'
import TextField from '@material-ui/core/TextField'
const DELIMITER = '-'
const MASK = '000-000-0000'
function removeTrailingCharIfFound(str: string, char): string {
return str
@stephenway
stephenway / log.shell
Created January 30, 2020 23:12
TSLint Member Ordering Warning
Warning: member-ordering - Direct string option is deprecated and does not support accessors.
See also https://palantir.github.io/tslint/rules/member-ordering/
You should replace "variables-before-functions"
with the following equivalent options and add -accessor categories as appropriate:
[
{
"name": "field",
"kinds": [
"public-static-field",
"protected-static-field",
@stephenway
stephenway / usePrevious.js
Created December 16, 2019 20:59
React Hook to Expose previous props for use in useEffect hook
import { useRef } from 'react'
const usePrevious = value => {
const ref = useRef()
useEffect(() => {
ref.current = value
})
return ref.current
}
/**
*
* AccountHolder Default Values
*/
import find from 'lodash.find'
import get from 'lodash.get'
import {
AccountHolderMutationVariables, AccountTypeEnum, GetAccountHolderQuery, GetPersonQuery
} from '@types-generated'
@stephenway
stephenway / README.md
Last active September 27, 2019 19:52
WIP: Convert FormikMultiWizard to React.FC & Context

React Compound Components

Source

  • [Original Formik Multistep Wizard Implementation][0]

Reference

  • [Compound React Components with Hooks + TypeScript][1]
  • [Guide to Typescript and Hooks][2]: A bit more basic but relevant
@stephenway
stephenway / _app.tsError.tsx
Created August 11, 2019 15:12
Next.js + Typescript Main App Class Errors
Class static side 'typeof MyApp' incorrectly extends base class static side 'typeof App'.
Types of property 'getInitialProps' are incompatible.
Type '({ Component, ctx }: any) => Promise<{ pageProps: {}; locale?: undefined; messages?: undefined; initialNow?: undefined; } | { query: any; authtoken: string; isLoggedIn: boolean; locale: any; messages: any; initialNow: number; pageProps?: undefined; } | { ...; }>' is not assignable to type '(context: NextAppContext<Record<string, string | string[] | undefined>, {}>) => Promise<DefaultAppIProps>'.
Type 'Promise<{ pageProps: {}; locale?: undefined; messages?: undefined; initialNow?: undefined; } | { query: any; authtoken: string; isLoggedIn: boolean; locale: any; messages: any; initialNow: number; pageProps?: undefined; } | { ...; }>' is not assignable to type 'Promise<DefaultAppIProps>'.
Type '{ pageProps: {}; locale?: undefined; messages?: undefined; initialNow?: undefined; } | { query: any; authtoken: string; isLoggedIn: boolean; locale: any;
@stephenway
stephenway / uniqueValidationMethod.js
Created August 9, 2019 22:22
Unique Method for Yup Validation
/*
* Author: @carlosagsmendes
* Source: https://github.com/jquense/yup/issues/345#issuecomment-487320558
*/
import yup from 'yup';
yup.addMethod(yup.array, 'unique', function (message, mapper = a => a) {
return this.test('unique', message, function (list) {
return list.length === new Set(list.map(mapper)).size;
@stephenway
stephenway / nestedArray.js
Created February 7, 2019 15:58
Flatten a nested array to a single level array
// Setup nested array
var array1 = [[1,2,[3]],4];
// Iterate over the nested array and reduce/concat
function flattenArray(arr1) {
return arr1.reduce((acc, val) => Array.isArray(val) ? acc.concat(flattenArray(val)) : acc.concat(val), []);
}
// Run the nested array through our function
flattenArray(array1);
body, h1, h2, h3, h4, h5, h6 {
color: #fff;
}
body {
margin-top: 0;
}
body,
.content {