Skip to content

Commit

Permalink
fix($callbacks): minor
Browse files Browse the repository at this point in the history
  • Loading branch information
faceyspacey committed Aug 3, 2017
1 parent f1cc307 commit a68488f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export default graphql(gql`
### `onBefore` + `onAfter`:
`onBefore/After` are callbacks called before and after the wrapped component loads on both `componentWillMount` and `componentWillReceiveProps`. This enables you to display `loading` indicators elsewhere in the UI.
`onBefore/After` are callbacks called before and after the wrapped component loads/changes on both `componentWillMount` and `componentWillReceiveProps`. This enables you to display `loading` indicators elsewhere in the UI.
If the component is already cached or you're on the server, they will both be called ***back to back synchronously***. They're both still called in this case for consistency. Each receives an `info` object, giving you full flexibility in terms of deciding what to do. Here are the keys on it:
Expand All @@ -306,7 +306,7 @@ const MyComponent = ({ dispatch, isLoading }) =>
</div>
```
> Keep in mind `setState` won't work synchronously during `componentWillMount` since the component is already in the middle of being rendered within the parent on which `this.setState` will be called. You can use *Redux* to call `dispatch` and that will affect child components. It's best to use this primarily for setting up and tearing down loading state on the client, and nothing more. If you chose to use them on the server, make sure the client renders the same thing on first load or you will have checksum mismatches.
> Keep in mind if you call `setState` within these callbacks and they are called during `componentWillMount`, the `state` change will have no effect for that render. This is because the component is already in the middle of being rendered within the parent on which `this.setState` will be called. You can use *Redux* to call `dispatch` and that will affect child components. However, it's best to use this primarily for setting up and tearing down loading state on the client, and nothing more. If you chose to use them on the server, make sure the client renders the same thing on first load or you will have checksum mismatches.
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export default function universal<Props: Props>(
isSync: boolean,
isServer?: boolean = false
) {
if (typeof this.props.onBefore === 'function') {
if (this.props.onBefore) {
const onBefore = this.props.onBefore
const info = { isMount, isSync, isServer }
onBefore(info)
Expand All @@ -176,7 +176,7 @@ export default function universal<Props: Props>(
if (Component && !error) {
hoist(UniversalComponent, Component, { preload: true })

if (this.props.onAfter === 'function') {
if (this.props.onAfter) {
const { onAfter } = this.props
const info = { isMount, isSync, isServer }
onAfter(info, Component)
Expand Down

0 comments on commit a68488f

Please sign in to comment.