Last active
June 18, 2018 05:25
Revisions
-
sijad revised this gist
Jun 18, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ import { Model, find, findAll } from 'react-jsonapi'; class User extends Model { name: string; -
sijad created this gist
Jun 18, 2018 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ var Model, Component, find, findAll, Loading; class User extends Model { name: string; email: string; createdAt: Date; } @find(User) @findAll(User, { // other options name: 'usersQuery', // prop name cachePolicy: 'network', // always send a new request to server }) class MyComponent extends Component { componentDidUpdate() { // Find(User) query result const { loading, result: user, } = this.props.data; if (!loading) { user.name = 'new name'; user.save(); } } render() { const { loading, // true if users query still loading result: users, // will contains [User] error, // etc } = this.props.users; if (loading) { return <Loading /> } return users.map(user => <DisplayUser key={user.id} user={user} />); } }