Skip to content

Allow loading prop on Rehydrated to accept null values #423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ lib
*.tgz
lerna-debug.log
.npmrc
.idea
50 changes: 50 additions & 0 deletions packages/aws-appsync-react/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
# aws-appsync-react

This package provides the following helpers which are needed when working with the SDK on a React project.

- `Rehydrated`
- `graphqlMutation`

----
## `Rehydrated`

A React component that you need to wrap your app with, when working with Apollo, React & a custom client created with `aws-appsync`. It makes sure
to wait for a client hydration in an offline environment.

### Import
```
import { Rehydrated } from 'aws-appsync-react'
```

### Props

| Prop name | Required | Details |
| ------------- |:-------------:| :-------|
| children | false | The React Element(s) to show when the client is fully hydrated |
| loading | false | The React Element to show while the client is hydrating. Defaults to the text element `Loading...` |
| render | false | A render-props function that has a single object parameter containing a boolean `rehydrated` and should return a React node. It's signature is: `({ rehydrated: boolean }) => React.ReactNode` |

Although the props `children` and `render` are mutually exclusive, **at least** one of them should be defined.


### Example
```
import { ApolloProvider } from 'react-apollo';
import { Rehydrated } from 'aws-appsync-react';
import App from './App';

const client = /* ... */

const WithProvider = () => (
<ApolloProvider client={client}>
<Rehydrated>
<App />
</Rehydrated>
</ApolloProvider>
)

export default WithProvider
```

## `graphqlMutation`

Full documentation for this helper can be found in the [Offline Helpers API page](https://github.com/awslabs/aws-mobile-appsync-sdk-js/blob/master/OFFLINE_HELPERS.md).
2 changes: 1 addition & 1 deletion packages/aws-appsync-react/src/rehydrated-rn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default class Rehydrated extends React.Component<RehydratedProps, Rehydra
if (render) return render({ rehydrated });

if (children) {
if (loading) return rehydrated ? children : loading;
if (loading !== undefined) return rehydrated ? children : loading;

return (
<Rehydrate rehydrated={rehydrated} style={style} >
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-appsync-react/src/rehydrated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class Rehydrated extends React.Component<RehydratedProps, Rehydra
if (render) return render({ rehydrated });

if (children) {
if (loading) return rehydrated ? children : loading;
if (loading !== undefined) return rehydrated ? children : loading;

return (
<Rehydrate rehydrated={rehydrated}>
Expand Down