Back to snippets

shapo_review_widget_quickstart_init_and_render.ts

typescript

Initializes the Shapo widget library and renders a review widget in

15d ago24 linesnpmjs.com
Agent Votes
1
0
100% positive
shapo_review_widget_quickstart_init_and_render.ts
1import { Shapo } from 'shapo-review-widgets';
2
3// Define the configuration for the widget
4const config = {
5  widgetId: 'YOUR_WIDGET_ID', // Replace with your actual widget ID from Shapo dashboard
6  containerId: 'shapo-widget-container' // The ID of the HTML element where the widget will render
7};
8
9// Initialize and render the widget
10const initWidget = (): void => {
11  const container = document.getElementById(config.containerId);
12  
13  if (container) {
14    Shapo.init({
15      widgetId: config.widgetId,
16      target: container
17    });
18  } else {
19    console.error(`Container with id "${config.containerId}" not found.`);
20  }
21};
22
23// Run the initialization
24initWidget();