@zerochain/sdk
Version:
The Züs JS SDK is a JavaScript client library that provides a convenient interface for interacting with the Züs Network. It allows developers to perform various operations such as creating and managing allocations, uploading and downloading files, executi
37 lines (32 loc) • 852 B
text/typescript
import { useCallback, useRef } from 'react'
import {
createWasmLoader,
type InitializeWasm,
type WasmLoaderOptions,
} from './createWasmLoader'
export const useWasmLoader = ({
onLog,
debounceTimeout,
setIsWasmLoaded,
}: {
onLog?: WasmLoaderOptions['onLog']
debounceTimeout?: WasmLoaderOptions['debounceTimeout']
setIsWasmLoaded?: WasmLoaderOptions['setIsWasmLoaded']
}): InitializeWasm => {
const retriesRef = useRef(0)
const getRetries = () => retriesRef.current
const incrementRetries = () => retriesRef.current++
const resetRetries = () => (retriesRef.current = 0)
const loadWasm = useCallback(
createWasmLoader({
onLog,
debounceTimeout,
setIsWasmLoaded,
getRetries,
incrementRetries,
resetRetries,
}),
[onLog, debounceTimeout, setIsWasmLoaded]
)
return loadWasm
}