use-assets
v1.1.6
Published
Assets import never been easier
Downloads
3
Maintainers
Readme
use-assets
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
Install
npm install --save use-assets
Usage
- 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>
);
};
Preview
gh pages (check the example folder in github for reference)
License
MIT © ShaharEli