Assets import never been easier ๐
No more searching for images paths in your project! ๐๐ ๐ปโโ๏ธ
useAssets will build assets tree for all the images in your src folder and import it to you automatically with cache
npm install --save use-assets
- Put all your images in the src folder (the order don`t matter use as many subdirs as you want)
- Make sure all images have unique name (the name of the pic is the key in the assets object)
- Enjoy
import * as React from "react";
import { useAssets } from "use-assets";
const Example = () => {
const { assets, loadingAssets, assetsPaths, assetsTree, assetsError } =
useAssets();
if (assetsError) {
return <span>Error occurred...</span>;
}
if (loadingAssets) {
return <span>Loading assets...</span>;
}
return (
<div>
<img src={assets.cow} />
</div>
);
};
gh pages (check the example folder in github for reference)
MIT ยฉ ShaharEli