Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
TS example: replace class extension of Query component (#2721)
Browse files Browse the repository at this point in the history
* Replace class extension of Query component

Extending the Query component as a class means that the compiled code
generates and extra object. By using the raw Query component directly
with generics, we avoid this extra artifact and the code becomes more
simple

* Changelog update
  • Loading branch information
evans authored and hwillson committed Jan 10, 2019
1 parent 8204605 commit 074779f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

### Improvements

- Update the typescript example app to use the raw Query component directly,
with generics, to avoid generating the extra object that's created (in the
compiled code) when extending the Query component as a class. <br/>
[@evans](https://github.com/evans) in [#2721](https://github.com/apollographql/react-apollo/pull/2721)


## 2.3.3

### Bug Fixes
Expand Down
6 changes: 2 additions & 4 deletions examples/typescript/src/Character.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { GetCharacterQuery, GetCharacterQueryVariables, Episode } from './__gene
import { GetCharacter as QUERY } from './queries';
import { Query } from 'react-apollo';

class CharacterQuery extends Query<GetCharacterQuery, GetCharacterQueryVariables> {}

export interface CharacterProps {
episode: Episode;
}
Expand All @@ -13,7 +11,7 @@ export const Character: React.SFC<CharacterProps> = props => {
const { episode } = props;

return (
<CharacterQuery query={QUERY} variables={{ episode }}>
<Query<GetCharacterQuery, GetCharacterQueryVariables> query={QUERY} variables={{ episode }}>
{({ loading, data, error }) => {
if (loading) return <div>Loading</div>;
if (error) return <h1>ERROR</h1>;
Expand All @@ -40,7 +38,7 @@ export const Character: React.SFC<CharacterProps> = props => {
</div>
);
}}
</CharacterQuery>
</Query>
);
};

Expand Down

0 comments on commit 074779f

Please sign in to comment.