Skip to content

Instantly share code, notes, and snippets.

Tanner Linsley tannerlinsley

Block or report user

Report or block tannerlinsley

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View react-testing-library.js
// utils/testing-library.js
// Set up a custom renderer for @testing-library/react
import { render as originalRender } from '@testing-library/react'
import diff from 'jest-diff'
import chalk from 'chalk'
const render = (...args) => {
const rendered = originalRender(...args)
@tannerlinsley
tannerlinsley / useKeyboardSpace.js
Last active Jan 21, 2020
A refactor of the old version as requested here in this tweet: https://twitter.com/sseraphini/status/1219701281331257345
View useKeyboardSpace.js
import React from 'react'
import PropTypes from 'prop-types'
import { Keyboard, LayoutAnimation, Dimensions, Platform } from 'react-native'
const defaultAnimation = {
duration: 500,
create: {
duration: 300,
type: LayoutAnimation.Types.easeInEaseOut,
property: LayoutAnimation.Properties.opacity,
@tannerlinsley
tannerlinsley / onWindowFocus.js
Created Jan 9, 2020
A utility function to detect window focusing without false positives from iframe focus events
View onWindowFocus.js
const state = {
added: false,
interval: false,
inFrame: false,
callbacks: []
}
export default function onWindowFocus(cb) {
state.callbacks.push(cb)
start()
View useDarkMode.js
import React from 'react'
export default function useDarkMode({
intervalTime = 300,
getIsDark = defaultGetIsDark,
} = {}) {
// Keep track of the current mode
const [isDark, setIsDark] = React.useState(() => getIsDark())
// Set up the checker
View useCalendar.js
import React from 'react'
import addDays from 'date-fns/add_days'
import isBefore from 'date-fns/is_before'
import isToday from 'date-fns/is_today'
import startOfDay from 'date-fns/start_of_day'
import differenceInCalendarMonths from 'date-fns/difference_in_calendar_months'
export default function useCalendar({
date = new Date(),
offset: userOffset = 0,
View useMicroMemo.js
export default function useMicroMemo() {
const memosRef = React.useRef(new Map());
return (id, updater, deps) => {
const memo = memosRef.current.get(id) || {};
let shouldUpdate;
if (!memo.deps) {
shouldUpdate = true;
} else if (deps.length !== memo.deps.length) {
@tannerlinsley
tannerlinsley / remove-linkin-connections.js
Created Jul 12, 2019
A script for removing LinkedIn connections automatically
View remove-linkin-connections.js
function removeFirstConnection () {
$('[type=ellipsis-horizontal-icon]').first().click()
setTimeout(() => {
$('.js-mn-connection-card__dropdown-delete-btn > button').click()
setTimeout(() => {
$('[data-control-name="confirm_removed"]').click()
}, 250)
}, 250)
}
View file.js
import React, { useReducer, useEffect, useState, useRef } from 'react'
import PropTypes from 'prop-types'
import { createSelector } from 'reselect'
import { connect } from 'react-redux'
import ReactTable from 'react-table'
import 'react-table/react-table.css'
import includes from 'ramda/src/includes'
import { DEBOUNCE_DELAY } from '../../../reference/constants'
import { loadContacts } from '../../../actions/v2/contactsActions'
import { useDebounce } from '../../../reference/hooks'
View hooks-as-middleware.js
const useLogout = () => {
// Use any store you want!
const [_, setStore] = Store.useStore()
// Have a localStorage hook?
const [_, setUserToken] = useLocalStorage('userToken')
// Have a router hook?
const { navigate } = useLocation()
View useMyPendingTodos.js
const useMyTodos = () => {
const [{ todos, myUserID }] = useStore()
// Only update when todos or myUserID updates
return useMemo(
() => todos.filter(todo =>
todo.userID === myUserID
),
[todos, myUserID]
)
You can’t perform that action at this time.