20CAKE20.JS
04-state

State

14

04-state/13-scope.tsx

Scope

Example

Official Cake20 View example for scope.

const clock = scope(() => {
  const now = cell(Date.now());
  const timer = window.setInterval(() => now(Date.now()), 1000);

  onScopeClose(() => window.clearInterval(timer));

  return { now };
});

export const onClose = clock.close;

export default () => <time>{new Date(clock.now()).toLocaleTimeString()}</time>;