Web SDK
- 概要
- はじめに
- v4からv5への移行
- ガイド
- フック
- useAddFundsModal
- useChain
- useCheckoutModal
- useCheckWaasFeeOptions
- useERC1155SaleContractCheckout
- useGetCoinPrices
- useGetCollectiblePrices
- useListAccounts
- useGetContractInfo
- useGetExchangeRate
- useGetSwapRoutes
- useGetSwapQuote
- useGetTransactionHistory
- useGetMultipleContractsInfo
- useGetTokenMetadata
- useMetadataClient
- useGetNativeTokenBalance
- useGetSingleTokenBalanceSummary
- useGetTransactionHistorySummary
- useIndexerClient
- useGetTokenBalancesByContract
- useGetTokenBalancesDetails
- useGetTokenBalancesSummary
- useIndexerGatewayClient
- useOpenConnectModal
- useOpenWalletModal
- useSelectPaymentModal
- useSignInEmail
- useStorage
- useSwapModal
- useTheme
- useWaasFeeOptions
- useWalletNavigation
- useWalletSettings
- useWallets
- 二次販売マーケットプレイス
- カスタム構成
- カスタムコネクタ
ゲームエンジンSDK
- Unity
- Unreal
その他のSDK
- Typescript
- Go
- モバイル
フック
useGetExchangeRate
USDから他通貨への現在の為替レートを取得するフック
インポート
import { useGetExchangeRate } from '@0xsequence/hooks'
使い方
import { useGetExchangeRate } from '@0xsequence/hooks'
function CurrencyConverter() {
const usdAmount = 100
const {
data: rate = 1,
isLoading,
error,
isError,
isSuccess
} = useGetExchangeRate('EUR')
if (isLoading) {
return <div>Loading rates...</div>
}
if (isError) {
return <div>Error: {error.message}</div>
}
return (
<div>
<h2>Currency Conversion</h2>
{isSuccess && (
<div>
<p>{usdAmount} USD = {usdAmount * rate} EUR</p>
<p>Current Rate: 1 USD = {rate} EUR</p>
</div>
)}
</div>
)
}
// Example with multiple currencies
function MultiCurrencyDisplay() {
const currencies = ['EUR', 'GBP', 'JPY']
return (
<div>
<h2>USD Exchange Rates</h2>
{currencies.map(currency => (
<CurrencyRate
key={currency}
currency={currency}
/>
))}
</div>
)
}
function CurrencyRate({ currency }) {
const { data: rate = 1 } = useGetExchangeRate(currency)
return (
<div>
1 USD = {rate} {currency}
</div>
)
}
パラメータ
toCurrency
string
対象となる通貨コード(例:‘EUR’, ‘GBP’, ‘JPY’)。‘USD’が指定された場合、変換レートは1を返します。
options
HooksOptions
(オプション)
interface HooksOptions {
retry?: boolean // Whether to retry failed requests (defaults to true)
disabled?: boolean // Whether to disable the query
}
返り値の型
このフックはReact Queryの結果オブジェクトを返します:
{
data: number // The exchange rate value from USD to target currency
isLoading: boolean // Whether the initial request is in progress
error: Error | null // Any error that occurred
isError: boolean // Whether an error occurred
isSuccess: boolean // Whether the request was successful
}
このページは役に立ちましたか?