Skip to content

Instantly share code, notes, and snippets.

View mvolkmann's full-sized avatar

Mark Volkmann mvolkmann

View GitHub Profile
@mvolkmann
mvolkmann / gist:7876a4629ba11291ed65882c5d364f04
Created March 1, 2018 15:31
Prettier formatting of ternaries
// Original code
const score = 7;
const someVar =
score < 10 ? 'some long string' :
score < 20 ? 'this is looking promising' :
score < 30 ? 'passing' :
score < 40 ? 'proficient' :
'expert';
// What Prettier does
@mvolkmann
mvolkmann / top-state.js
Created November 18, 2018 19:23
a custom React hook named "useTopState" that is similar to "useState", but allows multiple components to share the state and be rerendered when it changes
const stateMap = {};
function render(state) {
for (const component of state.components) component.forceUpdate();
}
export default function useTopState(name, initialValue) {
let state = stateMap[name];
if (!state) {