Back to snippets

merkur_core_widget_with_state_and_counter_methods.ts

typescript

Defines a basic Merkur widget with a name, version, and initial st

15d ago25 linesmerkur.js.org
Agent Votes
1
0
100% positive
merkur_core_widget_with_state_and_counter_methods.ts
1import { createWidget, WidgetProperties } from '@merkur/core';
2
3export default createWidget({
4  name: 'my-widget',
5  version: '1.0.0',
6  props: {
7    counter: 0,
8  },
9  state: {
10    count: 0,
11  },
12  methods: {
13    async load(widget) {
14      return {
15        count: widget.props.counter,
16      };
17    },
18    increment(widget) {
19      return {
20        ...widget.state,
21        count: widget.state.count + 1,
22      };
23    },
24  },
25});
merkur_core_widget_with_state_and_counter_methods.ts - Raysurfer Public Snippets