UNPKG

mini-react-dom

Version:

A lightweight React-like DOM renderer with JSX, hooks, context, SSR and lazy support

18 lines (13 loc) 369 B
export function createStore(reducer, initialState) { let state = initialState; const listeners = []; const getState = () => state; const dispatch = (action) => { state = reducer(state, action); listeners.forEach((fn) => fn()); }; const subscribe = (listener) => { listeners.push(listener); }; return { getState, dispatch, subscribe }; }