npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@daml/react

v2.10.6

Published

React framework to interact with a Daml ledger

Readme

@daml/react

React framework for Daml applications

Documentation

Comprehensive documentation for @daml/react can be found here.

Usage

The best way to get you started quickly is to use the create-daml-app template:

daml new --template=create-daml-app my-project-name

and to read the Quickstart Guide.

To get an overview on how to build a Daml application, please read the application architecture overview.

To use @daml/react your application needs to be connected to the JSON API of a Daml ledger. If your JSON API server for the ledger runs on the local host on port 7575, set

"proxy": "http://localhost:7575"

in your package.json and wrap your main component in the DamlLedger component of @daml/react

import DamlLedger from @daml/react

const App: React.FC = () => {
     <DamlLedger
      token: <your authentication token>
      httpBaseUrl?: <optional http base url>
      wsBaseUrl?: <optional websocket base url>
      reconnectThreshold?: <optional delay in ms>
      party: <the logged in party>
    >
      <MainScreen />
    </DamlLedger>
};

Now you can use the following React hooks to interact with a Daml ledger:

useParty

useParty returns the party, for which commands are currently send to the ledger.

const party = useParty();

useLedger

useLedger returns an instance of the Ledger class of @daml/ledger to interact with the Daml ledger.

const ledger = useLedger();
const newContract = await ledger.create(ContractTemplate, arguments);
const archiveEvent = await Ledger.archive(ContractTemplate, contractId);
const [choiceReturnValue, events] = await ledger.exercise(ContractChoice, contractId, choiceArguments);

useQuery

useQuery returns the contracts matching a given query. The query matches for a given contract template and specified field values of the contracts of that template.

const {contracts, loading} = useQuery(ContractTemplate, () => {field: value}, [dependency1,
dependency2, ...]);

If the query is omitted, all visible contracts of the given template are returned.

const {contracts, loading} = useQuery(ContractTemplate);

useReload

useReload returns a function to reload the results of queries.

const reload = useReload();
const onClick = reload;

useStreamQuery

Deprecated: prefer useStreamQueries

useStreamQuery has the same signature as useQuery, but it constantly refreshes the results.

const {contracts, loading} = useStreamQuery(ContractTemplate, () => {field: value}, [dependency1,
dependency2, ...]);

If the query is omitted, all visible contracts of the given template are returned.

const {contracts, loading} = useStreamQuery(ContractTemplate);

useStreamQueries

useStreamQueries is similar to useQuery, except that:

  • It constantly refreshes the results.
  • The factory function is expected to return a list of queries, and the resulting set of contracts is the union of all the contracts that match at least one query.
  • Like useQuery, if no factory function is provided, or if the provided function returns an empty array, the set will contain all contracts of that template.
const {contracts, loading} = useStreamQueries(ContractTemplate,
                                              () => [{field: value}, ...],
                                              [dependency1, dependency2, ...]);

You can additionally pass in an extra function to handle WebSocket connection failures.

useFetchByKey

useFetchByKey returns the unique contract of a given template and a given contract key.

const {contract, loading} = useFetchByKey(ContractTemplate, () => key, [dependency1, dependency2, ...]);

useStreamFetchByKey

Deprecated: prefer useStreamFetchByKeys

useStreamFetchByKey has the same signature as useFetchByKey, but it constantly keeps refreshing the result.

const {contract, loading} = useStreamFetchByKey(ContractTemplate, () => key, [dependency1, dependency2, ...]);

useStreamFetchByKeys

useStreamFetchByKeys takes a template and a factory that returns a list of keys, and returns a list of contracts that correspond to those keys (or null if no contract matches the corresponding key). This hook will keep an open WebSocket connection and listen for any change to the corresponding contracts.

If the factory function returns an empty array, the hook will similarly produce an empty array of contracts.

const {contracts, loading} = useStreamFetchByKeys(ContractTemplate,
                                                  () => [key1, key2, ...],
                                                  [dependency1, dependency2, ...]);

You can additionally pass in an extra function to handle WebSocket connection failures.

Advanced Usage

In order to interact as multiple parties or to connect to several ledgers, one needs to create an extra DamlLedger contexts specific to your requirement.

createLedgerContext

createLedgerContext returns another DamlLedger context and associated hooks (useParty, useLedger ... etc) that will look up their connection within that returned context.

Source

https://github.com/digital-asset/daml.

License

Apache-2.0