-
Notifications
You must be signed in to change notification settings - Fork 786
v2.1 Implemented the Query Component #1398
Changes from 1 commit
c50a56a
0e507a5
028f26e
23934e9
af7df0c
7d4ab66
44706a5
b1f6879
e1e49be
42c84d3
a48b79d
9e682f5
faf3993
581ffc2
c94afd2
9b2a5d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,16 +40,13 @@ export interface QueryProps { | |
skip?: Boolean; | ||
loading?: () => React.ReactNode; | ||
error?: (error: ApolloError) => React.ReactNode; | ||
render?: ((result: QueryRenderProp) => React.ReactNode); | ||
children?: ((result: QueryRenderProp) => React.ReactNode) | React.ReactNode; | ||
children?: (result: QueryRenderProp) => React.ReactNode; | ||
} | ||
|
||
export interface QueryState { | ||
result: any; | ||
} | ||
|
||
const isEmptyChildren = children => React.Children.count(children) === 0; | ||
|
||
function observableQueryFields(observable) { | ||
const fields = pick( | ||
observable, | ||
|
@@ -180,7 +177,7 @@ class Query extends React.Component<QueryProps, QueryState> { | |
}; | ||
|
||
render() { | ||
const { render, loading, error, children } = this.props; | ||
const { loading, error, children } = this.props; | ||
const result = this.getRenderProps(); | ||
|
||
if (result.loading && loading) { | ||
|
@@ -191,18 +188,8 @@ class Query extends React.Component<QueryProps, QueryState> { | |
return error(result.error); | ||
} | ||
|
||
if (render) { | ||
return render(result); | ||
} | ||
|
||
if (typeof children === 'function') { | ||
return children(result); | ||
} | ||
|
||
if (children && !isEmptyChildren(children)) | ||
return React.Children.only(children); | ||
|
||
return null; | ||
const renderedChildren = children(result); | ||
return renderedChildren && React.Children.only(renderedChildren); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still have to have this limitation with React 16? We could allow more than one resulting child since now React allows it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine with limiting to 16+ - but I'm on the progressive side. Not sure how other users would feel about it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say yes, since this will be part of a new version, a new API. And even then, you can still use it in previous versions, only that it will fail with a less clear error when you attempt to render multiple children than the one |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just put
getRenderProps
implementation into render. Alternatively you could keep it and rename it togetResult
to be consistent.