Skip to main content

React SDK

Getting Started

If you haven't already, please start with the Getting Started Guide below.

Installation

The first step is to install the Polls Platform React SDK.

npm install @polls-platform/react

Create a Poll

Once you have installed the SDK, you're ready to create your first poll.

import {  initializePolls,  DomainConfigType,  PollResponse,  createPoll,  Environment,} from "@polls-platform/react";initializePolls({  apiKey: "YOUR API KEY",  domainConfig: {    type: DomainConfigType.subdomain,    subdomain: "YOUR SUBDOMAIN",  },  environment: Environment.production,});// creating a poll is synchronous and instantaneousconst poll: PollResponse = createPoll({  title,  ownerId,  settings,  options,});// the poll can be opened immediately// in a new tab, or embedded in your siteconsole.log("Poll URL", poll.url);

Setting up Poll Data

The following is a more complete example of setting up fields for a poll.

import {  createPoll,  PollResponse,  OptionRequest,  OptionType,} from "@polls-platform/react";const options: OptionRequest[] = [  {    resourceId: "1", // the id of this resource in your system    title: "This is the first option",    type: OptionType.defaultTemplate,    subtitle: "Subtitles are displayed below the title",    details: "Descriptions are on the third line",    url: "https://example.com/1",    imageUrl: "https://example.com/images/1.png",  },  {    resourceId: "2", // the id of this resource in your system    title: "This is the second option",    type: OptionType.defaultTemplate,    subtitle: "Subtitles are displayed below the title",    details: "Descriptions are on the third line",    url: "https://example.com/2",    imageUrl: "https://example.com/images/2.png",  },];const poll: PollResponse = createPoll({  title: "Which one should we buy?",  ownerId: ownerId,  settings: {    multipleVotes: true,  },  options: options,});// endregionconsole.log("Poll", poll);

Opening the Poll

Continue to the next section to learn about the various options for opening the Poll.