Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jfbloom22's full-sized avatar

Jonathan Flower jfbloom22

View GitHub Profile
@jfbloom22
jfbloom22 / React Button Click Without Focus
Last active January 16, 2020 19:53
Accessible way to handle a React Bootstrap button click and avoid the focus border. Ref: https://github.com/react-bootstrap/react-bootstrap/issues/1300#issuecomment-386425763
onMouseDown={this.handleClick} onKeyUp={(e) => {if (e.keyCode === 13 || e.keyCode === 32) {this.handleClick()}}}
handleClick(e) { if (e) {e.preventDefault()}; }
@jfbloom22
jfbloom22 / configureStore.tsx
Last active June 20, 2019 20:10
Advanced redux configure store with redux-thunk, redux-offline, redux-persist v5, localForage, redux-devtools-extension, redux-immutable-state-invariant, axios, typescript, Trackjs, helper to persist date objects, redux-persist migrations
import {
applyMiddleware,
createStore,
Middleware,
Store,
AnyAction,
compose,
Reducer,
StoreEnhancer
} from 'redux';
@jfbloom22
jfbloom22 / actions.ts
Created October 4, 2018 13:33
Action creator with redux-thunk, redux-offline, and axios with typescript
import { ThunkAction } from 'redux-thunk';
import API from '../constants/apiEndpoints';
type ThunkResult<R> = ThunkAction<R, IinitialState, undefined, any>;
export function updateProduct(product: Iproduct): ThunkResult<void> {
return (dispatch, getState) => {
const originalProduct = getState().manageInventory.data.find(
prod => prod.id === product.id
);
// find() potentially returns undefined. Should never happen since we have to have a product in order to edit it.
@jfbloom22
jfbloom22 / configureStore.ts
Last active January 18, 2021 11:27
redux configure store with redux-thunk, redux-offline, redux-persist v5, localForage, redux-devtools-extension, redux-immutable-state-invariant, axios, and typescript
import {
applyMiddleware,
createStore,
Middleware,
Store,
AnyAction,
compose
} from 'redux';
import { createOffline } from '@redux-offline/redux-offline';
// use redux-persist v5 because it has built in support for migrations