Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrecabriere committed Mar 20, 2018
2 parents 47a9fd5 + 9f55283 commit 9757ce3
Showing 1 changed file with 3 additions and 33 deletions.
36 changes: 3 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ The **withData** HOC integrates apollo by wrapping your Component inside an Apol

#### Error handling
Since the graphql-data of the children components is fetched from the withData component, if errors appears in any query, they will be catched by the HOC and not re-dispatched to the child component.<br/>
So, **in the server-side rendering of a component, *this.props.data.error* will always be empty.**<br/>
So, **in the server-side rendering of a component, *this.props.data.error* is always empty.**<br/>
Because the withData HOC actually catches these errors, you can call *this.props.errors* **in the page component**. This property contains an array of all errors that occurred in children queries.<br/>
However, your errorss will still appear in the client-side rendering, so you can process them.
However, your errors will still appear in the client-side rendering, so you can process them.
```jsx
export default const MyChildComponentWithData = (props) => {
if (props.data.error) // always empty in the server-side rendering, but could contains errors whil client-processing
Expand Down Expand Up @@ -323,36 +323,6 @@ export default withGuard('logged', 'loggedAdmin')(MyComponentForLoggedAdminUsers

### 7.1 - Use decorators

Instead of wrapping the export of your Component inside HOCs, a good usage is to use ES6 decorators. To do such a thing, you have to use the *transform-decorators-legacy* babel plugin :
```
npm install --save-dev babel-plugin-transform-decorators-legacy
```

create or edit a .babelrc file at the root of your project
```diff
{
"presets": "next/babel",
"plugins": [
+ "babel-plugin-inline-import-graphql-ast"
]
}
```

You can now use ES6 decorators in your project :
```jsx
import { withData } from '../lib/next-apollo-hoc'

@withData
@graphql(myQuery)
export default class extends React.Component {
render() => (
<div>Component that will load data from a graphql endpoint</div>
)
}
```

### 7.1 - Use decorators

Instead of wrapping the export of your Component inside HOCs, you can use ES6 decorators. To do such a thing, you have to use the *transform-decorators-legacy* babel plugin :
```
npm install --save-dev babel-plugin-transform-decorators-legacy
Expand Down Expand Up @@ -426,4 +396,4 @@ You can download it on : [https://github.com/pierrecabriere/next-apollo-starter-
- ~~set a default token in config for authorize all requests (even unauthenticated)~~
- any idea ?

# 🚀
# 🚀

0 comments on commit 9757ce3

Please sign in to comment.