Skip to content

Commit b317f1f

Browse files
committed
doc: cleanup readme and reference new examples
1 parent 41da85c commit b317f1f

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,28 @@
33
<h1 align="center">react-lazy-svg</h1>
44
<p align="center" style="font-size: 1.2rem;">The easy way to use SVG sprite-sheets</p>
55

6-
[![GitHub license](https://img.shields.io/github/license/kaoDev/react-lazy-svg?style=flat-square)](https://github.com/kaoDev/react-lazy-svg)
6+
[![GitHub license](https://img.shields.io/github/license/kaoDev/react-lazy-svg?style=flat-square)](https://github.com/kaoDev/react-lazy-svg/blob/main/license.md)
77
[![npm](https://img.shields.io/npm/dm/react-lazy-svg?style=flat-square)](https://www.npmjs.com/package/react-lazy-svg)
88
[![npm](https://img.shields.io/npm/v/react-lazy-svg?style=flat-square)](https://www.npmjs.com/package/react-lazy-svg)
99
[![GitHub issues](https://img.shields.io/github/issues/kaoDev/react-lazy-svg?style=flat-square)](https://github.com/kaoDev/react-lazy-svg/issues)
10+
[![minified bundle size](https://img.shields.io/bundlephobia/minzip/react-lazy-svg?style=flat-square)](https://bundlephobia.com/package/react-lazy-svg)
1011

1112
react-lazy-svg is a simple way to use SVGs with the performance benefits of a
1213
sprite-sheet and svg css styling possibilities. Without bloating the bundle. It
1314
automatically creates a sprite-sheet for all used SVGs on the client but also
1415
provides a function to create a server side rendered sprite-sheet for icons used
15-
in the first paint.
16+
in the first paint. So you can inject the critical svg
1617

1718
## Usage
1819

1920
```bash
2021
npm install --save react-lazy-svg
2122
```
2223

24+
Examples on how to use react-lazy-svg with remix and next.js can be found in the
25+
[./example-nextjs/](./example-nextjs/) and [./example-remix/](./example-remix/)
26+
directory.
27+
2328
Wrap the App with the contextProvider and provide a function to resolve SVG
2429
strings by URL. If you are using server side rendering you should also call
2530
`initOnClient()` to hydrate the sprite sheet context.
@@ -46,26 +51,23 @@ contents from the file system.
4651

4752
```ts
4853
const svgIconFiles = new Map<string, string>();
54+
const readFile = promisify(fs.readFile);
55+
const cdnBase = 'http://localhost:3001/static/media/';
56+
4957
export const readSvg = async (url: string) => {
5058
if (svgIconFiles.has(url)) {
5159
return svgIconFiles.get(url);
5260
}
5361

54-
const readFile = promisify(fs.readFile);
55-
56-
const cdnBase = 'http://localhost:3001/static/media/';
57-
5862
if (url.startsWith(cdnBase)) {
5963
url = path.join(
6064
process.cwd(),
6165
url.replace(cdnBase, './build/public/static/media/'),
6266
);
63-
}
6467

65-
// ignore external assets on server side
66-
if (!url.startsWith('http')) {
6768
const svgString = await readFile(url, { encoding: 'utf8' });
6869
svgIconFiles.set(url, svgString);
70+
6971
return svgString;
7072
}
7173

0 commit comments

Comments
 (0)