20CAKE20.JS
04-state

State

14

04-state/02-watch.tsx

Watch

Example

Official Cake20 View example for watch.

export const data = {
  count: 0,
  profile: {
    name: "CAKE20",
  },
};

export const watch = {
  count(value: number, previous: number) {
    console.log("count", previous, value);
  },
  profile_name(value: string, previous: string) {
    console.log("name", previous, value);
  },
};

export default () => <Button onClick={() => data.count++}>{data.count}</Button>;