Skip to content

Commit 081aeb9

Browse files
committed
docs: update README with modern usage and installation instructions
1 parent 2c70a98 commit 081aeb9

File tree

1 file changed

+50
-20
lines changed

1 file changed

+50
-20
lines changed

README.md

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,62 @@
11
# React Isomorphic ScriptLoader
22

3-
React package to load scripts into your isomorphic (server side rendered) webapp.
3+
A lightweight React component to load scripts into your isomorphic (server-side rendered) web application.
4+
5+
## Features
6+
7+
- **Isomorphic/Universal**: Works on both server (SSR) and client.
8+
- **Modern Stack**: Built with TypeScript, supports React 18 and React 19.
9+
- **Zero Dependencies**: Lightweight and efficient.
10+
- **Typed**: Includes first-class TypeScript definitions.
411

512
## Installation
6-
```
13+
14+
```bash
15+
# npm
16+
npm install react-isomorphic-scriptloader
17+
18+
# yarn
719
yarn add react-isomorphic-scriptloader
20+
21+
# pnpm
22+
pnpm add react-isomorphic-scriptloader
823
```
924

10-
## Example Usage
11-
12-
```js
13-
import React from 'react'
14-
import Loader from 'react-isomorphic-scriptloader'
15-
16-
export default class MyComponent extends React.Component {
17-
state = { scriptsLoaded: false };
18-
render() {
19-
return (
20-
<div>
21-
<Loader src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places" onLoad={() => this.setState({ scriptsLoaded: true })} />
22-
{ this.state.scriptsLoaded && <div>Yayy google maps loaded</div> }
23-
{ !this.state.scriptsLoaded && <div>Please wait while google maps is being loaded</div> }
24-
</div>
25-
)
26-
}
25+
## Usage
26+
27+
### Functional Component (Hooks)
28+
29+
```tsx
30+
import React, { useState } from 'react';
31+
import ScriptLoader from 'react-isomorphic-scriptloader';
32+
33+
export default function MyComponent() {
34+
const [scriptsLoaded, setScriptsLoaded] = useState(false);
35+
36+
return (
37+
<div>
38+
<ScriptLoader
39+
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places"
40+
onLoad={() => setScriptsLoaded(true)}
41+
/>
42+
43+
{scriptsLoaded ? (
44+
<div>Google Maps Loaded!</div>
45+
) : (
46+
<div>Loading Maps...</div>
47+
)}
48+
</div>
49+
);
2750
}
2851
```
2952

53+
## Props
54+
55+
| Prop | Type | Description |
56+
|------|------|-------------|
57+
| `src` | `string` | The URL of the script to load. |
58+
| `onLoad` | `() => void` | Callback function executed when the script has loaded. |
59+
3060
## License
3161

32-
This package is licensed under the terms of MIT License. See the LICENSE file for further information.
62+
This package is licensed under the MIT License.

0 commit comments

Comments
 (0)