Docs-logo

Expo

Get Started
API Reference
Slash-shortcut-icon
Hamburger-icon

Asset

expo-asset provides an interface to Expo's asset system. An asset is any file that lives alongside the source code of your app that the app needs at runtime. Examples include images, fonts, and sounds. Expo's asset system integrates with React Native's, so that you can refer to files with require('path/to/file'). This is how you refer to static image files in React Native for use in an Image component, for example. Check out React Native's documentation on static image resources for more information. This method of referring to static image resources works out of the box with Expo.

Platform Compatibility

Android DeviceAndroid EmulatoriOS DeviceiOS SimulatorWeb
Status-success-iconStatus-success-iconStatus-success-iconStatus-success-iconStatus-success-icon

Installation

Terminal
→ expo install expo-asset

If you're installing this in a bare React Native app, you should also follow these additional installation instructions.

import { Asset } from 'expo-asset';

Arguments

NameTypeDescription
moduleIdsnumber | number[]-

Downloads and stores one or more assets locally. After the assets are loaded, this hook returns a list of asset instances. If something went wrong when loading the assets, an error is returned.

Info-icon
Note, the assets are not "reloaded" when you dynamically change the asset list.

Example

const [assets, error] = useAssets([require('path/to/asset.jpg'), require('path/to/other.png')]);

return assets ? <Image source={assets[0]} /> : null;

  • [Asset[] | undefined, Error | undefined]

Returns an array containing:

  • on the first position, a list of all loaded assets. If they aren't loaded yet, this value is undefined.
  • on the second position, an error which encountered when loading the assets. If there was no error, this value is undefined.

NameTypeDescription
hash
(optional)
string | null-
height
(optional)
number | null-
namestring-
typestring-
uristring-
width
(optional)
number | null-

NameTypeDescription
fileHashes
(optional)
string[]-
fileUris
(optional)
string[]-
hashstring-
height
(optional)
number-
httpServerLocationstring-
namestring-
scalesnumber[]-
typestring-
uri
(optional)
string-
width
(optional)
number-