@liqpro/liq-react

中文文档
0.83.0发布于 2026/11/02TypeScriptES Module

React hooks, mutations, and state management for the Liq perpetuals trading frontend.

原始使用文档
文档目录11 节
  1. Overview
  2. Key Exports
  3. Provider
  4. Query hooks (TanStack Query)
  5. Mutation hooks
  6. SSE / realtime
  7. Utilities
  8. Stores (Zustand)
  9. Install
  10. Peer Dependencies
  11. Build

@liq/react

React hooks, mutations, and state management for the Liq perpetuals trading frontend.

Overview

@liq/react wraps @liq/api-client and @liq/onchain in React Query queries, wagmi/viem mutations, and Zustand stores. It provides LiqProvider as the root context component, a set of data-fetching hooks for markets, positions, orders, and margin, and mutation hooks for order submission, cancellation, deposits, and gateway authentication. All async transaction flows are tracked via useTransactionStore.

Key Exports

Provider

  • LiqProvider — root provider (wraps React Query + gateway client context)
  • useLiqClient() — access the configured LiqClient instance
  • useLiqOnchain() — access the configured LiqOnchain instance

Query hooks (TanStack Query)

HookDescription
useMarketsQuery()Fetch all markets
useOpenOrdersQuery()Fetch open orders for current account
useAvailableMarginQuery()Fetch available margin for current account
useAccountId()Read SNX account ID
liqQueryKeysCache key factory for all queries

Margin (since 0.67.0):

HookDescription
useAccountMargin(accountId)Gateway margin — available, locked, free (free feeds validateOrder); needs the gateway session; refreshed on terminal order transitions too
useMarginUsage(accountId){ requiredInitialMargin, available, usage } read onchain; data undefined = no reading (isLoading in flight, fetchStatus === 'idle' disabled — not isPending), data.usage undefined = under water
useOrderMarginPreview(accountId, market, size, price, orderCost?)Protocol requiredMargin and estimated liquidation price at the tab's price (limit for LIMIT, mark for MARKET); the price moves the fees, the initial margin is valued at the contract's oracle; disabled without a connected wallet; re-reads every 10 s and goes stale on settle, deposit, withdraw and repay

Mutation hooks

HookDescription
useOrderSubmission()Submit an order draft — nonce, signing, retry, invalidation
useCancelOrderMutation()Cancel an open order
useDepositMutation()USDC → sUSDC → collateral deposit (onchain)
useWithdrawMutation()Collateral withdraw, repaying debt first if needed (onchain)
useCreateAccountMutation()Create SNX account NFT (onchain)
useClaimFaucetMutation()Claim testnet faucet tokens (onchain)
useGatewayAuthMutation()SIWE authentication → JWT
useTransactionMutation()Generic onchain tx wrapper with status tracking

Gasless relay (ADR-0063) — mount <LiqProvider relay> and the same mutation hooks above sign a Delegate7702 batch for the relayer to send and pay for, so the wallet never needs ETH. There is no separate set of hooks for this: the provider's sender picks wallet or relay, the hook doesn't know which.

SSE / realtime

  • useSseOrderUpdates(orderIds, callback) — live status updates of the listed orders, filtered from the orders:{accountId} channel (changing the list does not re-open the stream)
  • useAccountOrderUpdates(onUpdate?) — one subscription to the account-wide orders:{accountId} stream; the callback gets the full order_update with reason / origin

Utilities

  • useWallet() — active wallet address + chain ID
  • useNetworkId() — current network ID
  • useDebounce(value, delay) — debounce hook

Stores (Zustand)

  • useGatewayStore / selectIsAuthenticated — JWT + auth state
  • useTransactionStore / TransactionStatus / TransactionState / TransactionType — onchain tx lifecycle

Install

pnpm add @liq/react

Peer Dependencies

  • react ^18 or ^19
  • viem ^2
  • wagmi ^2

Build

moon run liq-react:build    # tsup → dist/

版本与发布记录

@liqpro/liq-react 共发布 53 个版本,首次发布于 2026/06/14;过去 12 个月发布了 53 个版本。

版本发布日期距今
0.83.0latest2026/11/021 天前
0.80.02026/10/295 天前
0.79.02026/10/277 天前
0.78.02026/10/2410 天前
0.77.02026/10/2410 天前
0.74.02026/10/2113 天前

关于 @liqpro/liq-react 的常见问题

@liqpro/liq-react 是什么?

React钩子、突变和Liq perpetual交易前端的状态管理。

如何安装 @liqpro/liq-react?

在项目目录运行 npm install @liqpro/liq-react,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:viem(^2.0.0)、react(^18.0.0 || ^19.0.0)、wagmi(^2.0.0)、@tanstack/react-query(^5.99.2)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@liqpro/liq-react 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@liqpro/liq-react 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@liqpro/liq-react 可以商用吗?

@liqpro/liq-react 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@liqpro/liq-react 还在维护吗?

最新版本 0.83.0 发布于 2026/11/02(1 天前);至今共发布 53 个版本,其中过去 12 个月发布了 53 个;首次发布于 2026/06/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。