Skip to content

Instantly share code, notes, and snippets.

👨‍🔬
Dreaming

Stephen Way stephenway

👨‍🔬
Dreaming
View GitHub Profile
View PhoneField.tsx
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 Jan 30, 2020
TSLint Member Ordering Warning
View log.shell
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 Dec 16, 2019
React Hook to Expose previous props for use in useEffect hook
View usePrevious.js
import { useRef } from 'react'
const usePrevious = value => {
const ref = useRef()
useEffect(() => {
ref.current = value
})
return ref.current
}
View AccountHolder.i.ts
/**
*
* 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 Sep 27, 2019
WIP: Convert FormikMultiWizard to React.FC & Context
View README.md

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 Aug 11, 2019
Next.js + Typescript Main App Class Errors
View _app.tsError.tsx
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 Aug 9, 2019
Unique Method for Yup Validation
View uniqueValidationMethod.js
/*
* 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 Feb 7, 2019
Flatten a nested array to a single level array
View nestedArray.js
// 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);
View graylogTV.css
body, h1, h2, h3, h4, h5, h6 {
color: #fff;
}
body {
margin-top: 0;
}
body,
.content {
You can’t perform that action at this time.