# React

The package `pollz-react` has been develop to integrate the Node.js SDK easily within a React app.

```
npm install pollz-react
```

```
yarn add pollz-react
```

The `PollzProvider` component wraps your React application, providing access to the Pollz SDK functionalities through React context. It initializes the SDK with the specified `appId` and `appSecret` and makes the SDK instance available to all child components.

#### `useAnonymousPoll`

* Fetches an anonymous poll using the provided `pollToken`.
* Returns the poll object and a function to refetch the poll.

#### `usePollTypes`

* Fetches all available poll types.
* Returns the list of poll types.

#### `usePoll`

* Fetches a specific poll using the provided `pollId`.
* Optionally listens for real-time updates on the poll.
* Returns the poll object and a function to refetch the poll.

#### `usePolls`

* Fetches a paginated list of all polls.
* Returns the list of polls and a function to refetch the list.

#### `usePollz`

* Retrieves the Pollz SDK instance and initialization status.
* Ensures that the component is wrapped within the `PollzProvider`.

### Usage Example:

```jsx
import React from 'react';
import { PollzProvider, usePolls, usePollz } from 'pollz-react';

const App = () => {
  const { polls, refetch: refetchPolls } = usePolls();
  const { initialized } = usePollz();

  if (!initialized) {
    return <div>Loading...</div>;
  }

  return (
    <div>
      <h1>Pollz React App</h1>
      <button onClick={() => refetchPolls()}>Refetch Polls</button>
      {/* Render your components using the fetched data */}
    </div>
  );
};

const PollzApp = () => (
  <PollzProvider appId="your-app-id" appSecret="your-app-secret">
    <App />
  </PollzProvider>
);

export default PollzApp;
```

This package provides a clean and convenient way for React developers to integrate Pollz functionality into their applications. If you have specific questions or need further assistance, feel free to let me know!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pollz.gitbook.io/pollz/tooling/react.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
