Skip to content

Instantly share code, notes, and snippets.

View evatrium's full-sized avatar

Weston Blair Ross evatrium

View GitHub Profile
import React, { Component } from "react";
import ReactDOM from "react-dom";
import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd";
// fake data generator
const getItems = count =>
Array.from({ length: count }, (v, k) => k).map(k => ({
id: `item-${k}`,
content: `item ${k}`
}));
@evatrium
evatrium / createState.js
Created July 8, 2020 01:57
simple global state for react
import {useCallback, useEffect, useState} from 'react';
const Subie = (subs = [], _unsub = it => subs.splice(subs.indexOf(it) >>> 0, 1)) => [
it => ((subs.push(it), () => _unsub(it))),
(...data) => subs.slice().map(f => (f(...data)))
];
const useForceUpdate = () => {
const [, set] = useState(Object.create(null));
return useCallback(() => {
import {h, render, Fragment, Host} from './little-vdom';
import {someSubscription, anotherSub} from './store';
const CounterAndSubscriber = (props, {count = 0}, update) => {
return( // in order to achieve hook-like functionality
// you can tie into the web component lifecycle
<Host lifeCycle={() => { //
// call update to rerender this component