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 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]
)
View useMyTodos.js
const useMyTodos = () => {
const [{ todos, myUserID }] = useStore()
// Only update when todos or myUserID updates
return useMemo(
() => todos.filter(todo =>
todo.userID === myUserID
),
[todos, myUserID]
)
View Counter.js
const useCount = () => {
const [{ count }, setState] = useStore();
const increment = () => {
setState(old => ({
...old,
count: old.count + 1
}));
}
View useAsyncIncrement.js
const useAsyncIncrement = () => {
const increment = useIncrement()
return async () => {
await new Promise(resolve => setTimeout(resolve, 1000))
increment()
}
}
View Counter.js
const useIncrement = () => {
const [state, setState] = useStore();
return () =>
setState(old => ({
...old,
count: old.count + 1
}));
}
View actions-example.js
const [Provider, useStore] = makeStore({
// Create actions that get the store as
// the first parameter
actions: {
increment: (state, amount = 1) => state.count + amount,
decrement: (state, amount = 1) => state.count - amount
}
})
// ...
You can’t perform that action at this time.