You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
2.3 KiB

{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/slicedToArray\";\nimport { useEffect, useState } from 'react';\nimport { Asset } from \"./Asset\";\nexport function useAssets(moduleIds) {\n var _useState = useState(),\n _useState2 = _slicedToArray(_useState, 2),\n assets = _useState2[0],\n setAssets = _useState2[1];\n var _useState3 = useState(),\n _useState4 = _slicedToArray(_useState3, 2),\n error = _useState4[0],\n setError = _useState4[1];\n useEffect(function () {\n Asset.loadAsync(moduleIds).then(setAssets).catch(setError);\n }, []);\n return [assets, error];\n}","map":{"version":3,"sources":["../src/AssetHooks.ts"],"names":[],"mappings":";AAAA,SAAS,SAAS,EAAE,QAAQ,QAAQ,OAAO;AAE3C,SAAS,KAAK;AAuBd,OAAM,SAAU,SAAS,CAAC,SAA4B,EAAA;EACpD,gBAA4B,QAAQ,EAAW;IAAA;IAAxC,MAAM;IAAE,SAAS;EACxB,iBAA0B,QAAQ,EAAS;IAAA;IAApC,KAAK;IAAE,QAAQ;EAEtB,SAAS,CAAC,YAAK;IACb,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC;EAC5D,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC;AACxB","sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { Asset } from './Asset';\n\n// @needsAudit\n/**\n * Downloads and stores one or more assets locally.\n * After the assets are loaded, this hook returns a list of asset instances.\n * If something went wrong when loading the assets, an error is returned.\n *\n * > Note, the assets are not \"reloaded\" when you dynamically change the asset list.\n *\n * @return Returns an array containing:\n * - on the first position, a list of all loaded assets. If they aren't loaded yet, this value is\n * `undefined`.\n * - on the second position, an error which encountered when loading the assets. If there was no\n * error, this value is `undefined`.\n *\n * @example\n * ```tsx\n * const [assets, error] = useAssets([require('path/to/asset.jpg'), require('path/to/other.png')]);\n *\n * return assets ? <Image source={assets[0]} /> : null;\n * ```\n */\nexport function useAssets(moduleIds: number | number[]): [Asset[] | undefined, Error | undefined] {\n const [assets, setAssets] = useState<Asset[]>();\n const [error, setError] = useState<Error>();\n\n useEffect(() => {\n Asset.loadAsync(moduleIds).then(setAssets).catch(setError);\n }, []);\n\n return [assets, error];\n}\n"],"sourceRoot":""},"metadata":{},"sourceType":"module"}