UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

32 lines (31 loc) 666 B
import { useState as k, useCallback as e } from "react"; function f(u = [], n) { const [t, c] = k(u), l = e( (r) => { c((s) => { const o = [...s, r]; return n && o.length > n && o.shift(), o; }); }, [n] ), p = e(() => { if (t.length === 0) return; const r = t[t.length - 1]; return c((s) => s.slice(0, -1)), r; }, [t]), h = e(() => t[t.length - 1], [t]), a = e(() => { c([]); }, []), i = e(() => t.length === 0, [t]); return { stack: t, push: l, pop: p, clear: a, peek: h, size: t.length, isEmpty: i }; } export { f as useStack }; //# sourceMappingURL=useStack.js.map