Handling events

In your application, you'll need to listen and respond to different events emitted by the CSPR.click library. On this page, we're covering the most common. Check the Events page in the Web SDK reference for a full list of events.

The following code shows an example of how to bind your handlers to the CSPR.click events:

useEffect(() => {
  clickRef?.on('csprclick:signed_in', async (evt) => {
    // update your app accordingly
  });
  clickRef?.on('csprclick:signed_out', async (evt) => {
    // update your app accordingly
  });
}, [clickRef?.on]);

csprclick:signed_in

This event is emitted every time the CSPR.click library connects to an account. The previous state was disconnected.

csprclick:signed_in reference.

csprclick:switched_account

This event is emitted every time the CSPR.click livrary switches connection from one account to another.

csprclick:switched_account reference.

csprclick:signed_out

This event is emitted when the CSPR.click library disconnects the active account due to a call to the signOut() SDK method.

csprclick:signed_out reference.

csprclick:disconnected

This event is emitted when CSPR.click library receives a disconnect request or event from the connected wallet. The app should close the current session as a consequence of this event.

Receives the provider that has been disconnected.

csprclick:disconnected reference.

Last updated