# useNotifications

A hook containing tools to add, remove, and fetch notifications.

```javascript
import { useNotifications } from 'useink/notifications'

export const MyNotifications = ({ children }) => {
  const { notifications, addNotification, removeNotification } = useNotifications()

  return (
    <div>
      <button
        onClick={() => {
          addNotification({ message: 'hello from the ink! team 🦑', type: 'None' })
        }}
      >
        Say hello
      </button>

      <ul>
        {notifications.map((n) => (
          <li key={n.id} onClick={() => removeNotification(n.id)}>
            {n.message}
          </li>
        ))}
      </ul>
    </div>
  )
}
```

### Return Type[​](https://use.ink/frontend/notifications/useNotifications#return-type) <a href="#return-type" id="return-type"></a>

```javascript
// Returns
interface UseNotifications {
  notifications: {
    id: string;
    createdAt: number;
    type: NotificationType;
    message: string;
    // Raw types from PolkadotJs
    result?: Codec | ISubmittableResult;
    chain?: ChainId; 
  }[];
  addNotification: (payload: AddNotificationPayload) => void;
  removeNotification: (id: string) => void;
}

interface AddNotificationPayload {
  type: NotificationType;
  message: string;
  result?: Codec | ISubmittableResult;
  chain?: ChainId;
}

type NotificationType =
  | 'None'
  | 'WalletConnected'
  | 'WalletDisconnected'
  | 'DryRun'
  | 'PendingSignature'
  | 'Errored' // Used for custom JavaScript errors
     // Potential transaction statuses
  | 'Future' | 'Ready' | 'Broadcast' | 'InBlock' | 'Retracted' | 'FinalityTimeout' | 'Finalized' | 'Usurped' | 'Dropped' | 'Invalid';
```


---

# 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://lunes-labs.gitbook.io/dao-lunes-labs-pt/developers/para-desenvolvedores/smart-contract-ink-4.x/frontend-development/useink-notifications/usenotifications.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.
