react-isomorphic-scriptloader
Advanced tools
+1
-1
| { | ||
| "name": "react-isomorphic-scriptloader", | ||
| "version": "3.0.0", | ||
| "version": "3.0.1", | ||
| "description": "Load scripts with ease", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
+48
-18
| # React Isomorphic ScriptLoader | ||
| React package to load scripts into your isomorphic (server side rendered) webapp. | ||
| A lightweight React component to load scripts into your isomorphic (server-side rendered) web application. | ||
| ## Features | ||
| - **Isomorphic/Universal**: Works on both server (SSR) and client. | ||
| - **Modern Stack**: Built with TypeScript, supports React 18 and React 19. | ||
| - **Zero Dependencies**: Lightweight and efficient. | ||
| - **Typed**: Includes first-class TypeScript definitions. | ||
| ## Installation | ||
| ``` | ||
| ```bash | ||
| # npm | ||
| npm install react-isomorphic-scriptloader | ||
| # yarn | ||
| yarn add react-isomorphic-scriptloader | ||
| # pnpm | ||
| pnpm add react-isomorphic-scriptloader | ||
| ``` | ||
| ## Example Usage | ||
| ## Usage | ||
| ```js | ||
| import React from 'react' | ||
| import Loader from 'react-isomorphic-scriptloader' | ||
| ### Functional Component (Hooks) | ||
| export default class MyComponent extends React.Component { | ||
| state = { scriptsLoaded: false }; | ||
| render() { | ||
| return ( | ||
| <div> | ||
| <Loader src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places" onLoad={() => this.setState({ scriptsLoaded: true })} /> | ||
| { this.state.scriptsLoaded && <div>Yayy google maps loaded</div> } | ||
| { !this.state.scriptsLoaded && <div>Please wait while google maps is being loaded</div> } | ||
| </div> | ||
| ) | ||
| } | ||
| ```tsx | ||
| import React, { useState } from 'react'; | ||
| import ScriptLoader from 'react-isomorphic-scriptloader'; | ||
| export default function MyComponent() { | ||
| const [scriptsLoaded, setScriptsLoaded] = useState(false); | ||
| return ( | ||
| <div> | ||
| <ScriptLoader | ||
| src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places" | ||
| onLoad={() => setScriptsLoaded(true)} | ||
| /> | ||
| {scriptsLoaded ? ( | ||
| <div>Google Maps Loaded!</div> | ||
| ) : ( | ||
| <div>Loading Maps...</div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
| ``` | ||
| ## Props | ||
| | Prop | Type | Description | | ||
| |------|------|-------------| | ||
| | `src` | `string` | The URL of the script to load. | | ||
| | `onLoad` | `() => void` | Callback function executed when the script has loaded. | | ||
| ## License | ||
| This package is licensed under the terms of MIT License. See the LICENSE file for further information. | ||
| This package is licensed under the MIT License. |
9185
6.75%63
90.91%