Skip to content

Instantly share code, notes, and snippets.

View jeffellis's full-sized avatar

jeffellis

  • Rally - Broadcom
View GitHub Profile
@jeffellis
jeffellis / Dispatcher.js
Created March 14, 2018 16:34
Michael's withDispatch wrapper
import React, { Component } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
const mapStateToProps = (state) => ({});
export function withDispatch(WrappedComponent, actions) {
class Dispatcher extends Component {
render() {
@jeffellis
jeffellis / PropCheck.js
Created June 14, 2020 11:30
React: Determine Which Props Caused a Render in a Class Component
componentWillReceiveProps(nextProps) {
for (const index in nextProps) {
if (nextProps[index] !== this.props[index]) {
console.log(index, this.props[index], '-->', nextProps[index]);
}
}
}
@jeffellis
jeffellis / centered-div.css
Last active July 6, 2020 18:43
Center everything in a div
.center-everything-in-div {
display: flex;
align-items: center;
justify-content: center;
min-height: 100%;
}
@jeffellis
jeffellis / useResizeObserver.js
Created July 16, 2020 18:24
React hook for using a single ResizeObserver for multiple subscriptions
import React from 'react';
import ResizeObserver from 'resize-observer-polyfill';
let resizeObserver;
const subscriptions = {};
const onResizeCallback = elements => {
elements.forEach(element => {
const id = element.target.id;
const callback = subscriptions[id] && subscriptions[id].callback;
@jeffellis
jeffellis / GmailInboxScripts.js
Last active September 27, 2021 15:49
Gmail script to move phishing emails to trash
function processInbox() {
// process all recent threads in the Inbox (see comment to this answer)
var threads = GmailApp.search("newer_than:1d");
for (var i = 0; i < threads.length; i++) {
// get all messages in a given thread
var messages = threads[i].getMessages();
for (var j = 0; j < messages.length; j++) {
var message = messages[j];
processMessage(message);
}
@jeffellis
jeffellis / useLogPropDiffs.js
Created September 27, 2021 17:19
Hook for logging prop diffs in a functional component
import { useEffect, useRef } from 'react';
const useLogPropDiffs = (props, label = '') => {
const previousProps = useRef({});
useEffect(() => {
previousProps.current = props;
});
if (previousProps.current) {