0.2.3 • Published 3 years ago

react-script-fall v0.2.3

Weekly downloads
14
License
MIT
Repository
github
Last release
3 years ago

react-script-fall

react-script-fall is a <script> tag loader

  • Declarative loading order control
  • SSR safe

react@^16.8 is required

npm install react-script-fall

Why

As far as I known, script tag's async attribute can not be set 'false, so we need something to control this.

Usage

simple

<Script src="https://cdn-dependency" onLoad={(loaded) => console.log({loaded})}>
  <Script src="https://cdn" async/>
</Script>

real world

const InitSomething: FunctionComponent<{initializeSomething(): void}> = props => {
  const [loaded, setLoaded] = useState(0)
  const handleLoad = (loaded) => loaded && setLoaded(loaded + 1)
  useEffect(() => {
    if (loaded === 2) {
      // todo initialize something
      props.initializeSomething()
    }
  }, [loaded])
  return (
    <Script src="https://cdn-dependency" onLoad={handleLoad}>
      <Script src="https://cdn" onLoad={handleLoad}/>
    </Script>
  )
}

License

MIT

0.2.3

3 years ago

0.2.1

4 years ago

0.2.2

4 years ago

0.2.0

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago