@@ -15,20 +15,20 @@ it will create the script tag you've requested.
1515is a pre-existing ` <script> ` tag for that URL that it didn't create. If ` src `
1616prop changes, it will load that new URL.
1717
18- ## Version notes
18+ # Version notes
1919
2020- supports React 15 or 16
2121- if building for legacy browsers with a bundler like Webpack that supports the
2222 ` module ` field of ` package.json ` , you will probably need to add a rule to
2323 transpile this package.
2424
25- ## Installation
25+ # Installation
2626
2727``` sh
2828npm install --save react-render-props-script-loader
2929```
3030
31- ## Example
31+ # Example
3232
3333``` js
3434import * as React from ' react'
@@ -52,9 +52,13 @@ export const MapViewContainer = props => (
5252)
5353```
5454
55- ## API
55+ # API
5656
57- The package exports a single component with the following props:
57+ ## ` ScriptLoader `
58+
59+ ``` js
60+ import ScriptLoader from ' react-render-props-script-loader'
61+ ```
5862
5963### ` src ` (** required** ` string ` )
6064
@@ -73,3 +77,48 @@ script
7377
7478The render function. It will be called with an object having the following
7579props, and may return your desired content to display:
80+
81+ ``` js
82+ {
83+ loading: boolean,
84+ loaded: boolean,
85+ error: ? Error ,
86+ promise: ? Promise < any> ,
87+ }
88+ ` ` `
89+
90+ ## Server-Side Rendering
91+
92+ ` ` ` js
93+ import {
94+ ScriptsRegistry ,
95+ ScriptsRegistryContext ,
96+ } from ' react-render-props-script-loader'
97+ ` ` `
98+
99+ On the server, create an instance of ` ScriptsRegistry` and put it on the app's
100+ context:
101+
102+ ` ` ` js
103+ const registry = new ScriptsRegistry ()
104+
105+ const body = ReactDOM .renderToString (
106+ < ScriptsRegistryContext .Provider value= {registry}>
107+ < App / >
108+ < / ScriptsRegistryContext .Provider >
109+ )
110+ ` ` `
111+
112+ Then render ` registry .scriptTags ()` in your head element:
113+
114+ ` ` ` js
115+ const html = (
116+ < html className= " default" >
117+ < head>
118+ ...
119+ {registry .scriptTags ()}
120+ < / head>
121+ ...
122+ < / html>
123+ )
124+ ` ` `
0 commit comments