Skip to content

Commit baf6682

Browse files
authored
Merge pull request #73 from smooth-code/various-fixes
Various fixes
2 parents 468691f + a643035 commit baf6682

20 files changed

+2308
-415
lines changed

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ node_modules/
22
/coverage/
33
/dist/
44
__fixtures__/
5-
/example/
65
CHANGELOG.md
76
package.json

README.md

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,7 @@ window.snapSaveState = () => getState()
342342

343343
### Hot Reloading
344344

345-
Loadable Components is Hot Reload friendly, it works out of the box with [React Hot Loader](https://github.com/gaearon/react-hot-loader) without adding a single line of code. All components are loaded when a reload occurs, if you want to disable this behaviour, you can set a global config:
346-
347-
```js
348-
import { setConfig } from 'loadable-components'
349-
350-
// Disable automatic "load" of components
351-
setConfig({ hotReload: false })
352-
```
345+
Loadable Components is Hot Reload friendly, it works out of the box with [React Hot Loader](https://github.com/gaearon/react-hot-loader).
353346

354347
## API Reference
355348

@@ -359,15 +352,15 @@ This is the default export. It's a factory used to create a loadable component.
359352

360353
### Arguments
361354

362-
1. `getComponent` _(Function)_: Function to load component asynchronously.
363-
2. `options` _(Object)_: Facultative options to configure component behavior.
355+
1. `getComponent` _(Function)_: Function to load component asynchronously.
356+
2. `options` _(Object)_: Facultative options to configure component behavior.
364357

365358
### options
366359

367-
1. `ErrorComponent` _(ReactComponent)_: Component rendered when an error occurs, take two props: `error` and `ownProps`.
368-
2. `LoadingComponent` _(ReactComponent)_: Component rendered during loading, take the same props from loadable component.
369-
3. `render` _(Function)_: If specified this function is called with in render with an object: `{ loading, error, ownProps, Component }`. It takes precedence over `ErrorComponent` and `LoadingComponent`.
370-
4. `modules` _(Object)_: This options is only required if you do server-side rendering. It can be automated using babel plugin `loadable-components/babel`.
360+
1. `ErrorComponent` _(ReactComponent)_: Component rendered when an error occurs, take two props: `error` and `ownProps`.
361+
2. `LoadingComponent` _(ReactComponent)_: Component rendered during loading, take the same props from loadable component.
362+
3. `render` _(Function)_: If specified this function is called with in render with an object: `{ loading, error, ownProps, Component }`. It takes precedence over `ErrorComponent` and `LoadingComponent`.
363+
4. `modules` _(Object)_: This options is only required if you do server-side rendering. It can be automated using babel plugin `loadable-components/babel`.
371364

372365
```js
373366
import loadable from 'loadable-components'

example/App.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import React from 'react'
22
import loadable from 'loadable-components'
3+
import { hot } from 'react-hot-loader'
34

4-
const AsyncWhat = loadable(() => import('./What.js'))
5+
const AsyncWhat = loadable(() =>
6+
import(/* webpackChunkName: "What" */ './What.js'),
7+
)
8+
9+
const AsyncBig = loadable(() =>
10+
import(/* webpackChunkName: "Big" */ './Big.js'),
11+
)
512

613
const App = () => (
714
<div>
815
Hello <AsyncWhat />!
916
</div>
1017
)
1118

12-
export default App
19+
export default hot(module)(App)

example/Big.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const Big = () => 'Big'
2+
3+
export default Big

example/Counter.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react'
2+
3+
class Counter extends React.Component {
4+
state = { count: 0 }
5+
6+
componentDidMount() {
7+
this.interval = setInterval(
8+
() =>
9+
this.setState(previousState => ({ count: previousState.count + 1 })),
10+
500,
11+
)
12+
}
13+
14+
componentWillUnmount() {
15+
clearInterval(this.interval)
16+
}
17+
18+
render() {
19+
return this.state.count
20+
}
21+
}
22+
23+
export default Counter

example/DeepWorld.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

example/What.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import loadable from 'loadable-components'
33

44
const What = loadable(
55
async () => {
6-
const { default: DeepWord } = await import('./DeepWorld')
7-
const { default: DeepAmazing } = await import('./DeepAmazing')
6+
const {
7+
default: World,
8+
} = await import(/* webpackChunkName: "World" */ './World')
9+
const {
10+
default: Amazing,
11+
} = await import(/* webpackChunkName: "Amazing" */ './Amazing')
812
return () => (
913
<React.Fragment>
10-
<DeepAmazing /> <DeepWord />
14+
<Amazing /> <World />
1115
</React.Fragment>
1216
)
1317
},

example/World.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import Counter from './Counter'
3+
4+
const World = () => (
5+
<React.Fragment>
6+
<Counter /> World
7+
</React.Fragment>
8+
)
9+
10+
export default World

example/nodemon.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"execMap": {
33
"js": "babel-node"
4-
}
4+
},
5+
"delay": 10000
56
}

0 commit comments

Comments
 (0)