Functions & Hooks

useImageState

function useImageState(source: string | number): ImageState;

Load an image source into a native handle, with its loading and error state.

Accepts a require('./pic.png') asset, an http(s)://, file://, data: or asset:/content: URI, a raw base64 string, or an SVG document as markup.

A local file is opened natively, so its bytes never enter JS at all. Only a remote or Metro-served URI still goes through fetch, and then as an ArrayBuffer - nothing is ever base64-encoded on the JS thread.

data is cleared the moment source changes, so a slow or failing load can never leave the previous image on screen. The handle is disposed when the source changes or the component unmounts.

Parameters

source

string | number

Returns

ImageState

On this page