Last active
July 21, 2017 21:21
-
-
Save glortho/2baa82c84bdbea96a981f5d7fca56381 to your computer and use it in GitHub Desktop.
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 characters
import React from 'react'; | |
import { Api } from 'jetset'; | |
function create( users ) { | |
users | |
.create({ name: 'foo' }) | |
.then( data => console.log( 'Successfully created', data ) ); | |
} | |
function Users({ users }) { | |
return ( | |
<div> | |
{ users.list().isPending ? | |
<span>Loading...</span> | |
: | |
<span> | |
{users.list().data.map( user => | |
<div key={ user.data.id }> | |
<span>{ user.data.name }</span> | |
<button onClick={ user.delete }>Delete</button> | |
</div> | |
)} | |
<button onClick={() => create( users )}>New foo</button> | |
<button onClick={() => users.list().clear()}>Clear cache</button> | |
</span> | |
} | |
</div> | |
); | |
} | |
export default function ApiCollectionsExample() { | |
return ( | |
<Api url="https://jsonplaceholder.typicode.com" users="/users"> | |
<Users /> | |
</Api> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment