> For the complete documentation index, see [llms.txt](https://lunes-labs.gitbook.io/dao-lunes-labs-pt/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lunes-labs.gitbook.io/dao-lunes-labs-pt/developers/para-desenvolvedores/smart-contract-ink-4.x/frontend-development/hooks/contracts/useevents.md).

# useEvents

A hook for fetching contract events from state after you have subscribed by calling [useEventSubscription](https://use.ink/frontend/core/hooks/contracts/use-event-subscription). You can filter for specific events by passing in a case-sensitive array of event names.

### Usage[​](https://use.ink/frontend/react/hooks/contracts/use-events#usage) <a href="#usage" id="usage"></a>

```javascript
import { useEvents, useEventSubscription, useContract } from 'useink'
import metadata from 'metadata.json'

const CONTRACT_ADDRESS = '..'

export const MyContractView: React.FC = () => {
  const contract = useContract(CONTRACT_ADDRESS, metadata)
  useEventSubscription(contract) // Only subscribe to a contract's events one time.
  const { events: allContractEvents } = useEvents(contract?.address) // fetch a specific contracts events from state
  const { events: fooBarEvents } = useEvents(contract?.address, ['Foo', 'Bar']) // only fetch Events Foo and Bar from state

  return (
    <div>
      <ul>
        {allContractEvents.map(e => (
          <li key={e.id}>
            {e.name}: Do something with the args -> {JSON.stringify(e.args)}
          </li>
        ))}
      </ul>

      <ul>
        {fooBarEvents.map(e => (
          <li key={e.id}>
            {e.name}: Do something with the args -> {JSON.stringify(e.args)}
          </li>
        ))}
      </ul>
    </div>
  )
}
```

### Return Value[​](https://use.ink/frontend/react/hooks/contracts/use-events#return-value) <a href="#return-value" id="return-value"></a>

```javascript
{
  events: {
      id: string;
      createdAt: number;
      name: string; // The name of the event emitted
      args: unknown[]; // human-readable values emitted in the event
    }[];
  // A function to remove an event from state. Useful when a user closes a snackbar notification, etc
  removeEvent: (args: { address: string, id: string }) => void;
}
```
