Skip to content

Instantly share code, notes, and snippets.

View asbjornh's full-sized avatar

Asbjørn Hegdahl asbjornh

View GitHub Profile
@asbjornh
asbjornh / 1.js
Created April 26, 2019 06:51
Babel examples
const { generate, parse, t, traverse } = require('./babel');
const source = `
const babel = "cool";
function test(babel) {
return babel;
}
`;
// var babel = "cool";
@asbjornh
asbjornh / _ use-actions.js
Last active April 26, 2019 06:59
useActions: custom React hook
import React from 'react';
const useActions = (actions, initialState) => {
const [state, setState] = React.useState(initialState);
const functions = Object.entries(actions).reduce(
(accumulator, [name, action]) => ({
...accumulator,
[name]: () => setState(action)
}),
{}