Skip to content

watchConnectors

Action for watching changes to the available Starknet connectors.

Import

import { watchConnectors } from "starkweb/core";

Usage

index.ts
import { watchConnectors } from "starkweb/core";
import { config } from "./config";
 
const unwatch = watchConnectors(config, {
  onChange(connectors, prevConnectors) { 
    console.log('Connectors changed:', connectors); 
    console.log('Previous connectors:', prevConnectors); 
  }, 
});

Parameters

import { type WatchConnectorsParameters } from "starkweb/core";

onChange

(connectors: GetConnectorsReturnType, prevConnectors: GetConnectorsReturnType) => void

Callback function that is called when the available connectors change. Receives the new connectors and previous connectors as arguments.

index.ts
import { watchConnectors } from "starkweb/core";
import { config } from "./config";
 
const unwatch = watchConnectors(config, {
  onChange(connectors, prevConnectors) { 
    console.log('Connectors changed:', connectors); 
    console.log('Previous connectors:', prevConnectors); 
  }, 
});

Return Type

import { type WatchConnectorsReturnType } from "starkweb/core";

() => void

Function to stop watching for connector changes.

Example

example.ts
import { watchConnectors } from "starkweb/core";
import { config } from "./config";
 
// Start watching connector changes
const unwatch = watchConnectors(config, {
  onChange(connectors, prevConnectors) { 
    const newConnectors = connectors.filter(
      connector => !prevConnectors.find(prev => prev.id === connector.id)
    );
    console.log('New connectors:', newConnectors);
  }, 
});
 
// Later: stop watching
unwatch();