Last active
July 21, 2017 21:23
-
-
Save glortho/8bba60a8f55e81e68fa5431b7944e7d0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { users } from './api_decorator'; | |
@users | |
export default class ApiSearchExample extends React.Component { | |
constructor( props ) { | |
super( props ); | |
this.state = { username: '' }; | |
} | |
onSubmit = event => { | |
event.preventDefault(); | |
this.setState( | |
{ username: this.refs.input.value }, | |
() => this.props.users.search( this.state ) | |
); | |
} | |
render() { | |
const results = this.props.users.search.results( this.state ); | |
return ( | |
<div> | |
<div> | |
<form onSubmit={ this.onSubmit }> | |
<input ref="input" type="text" placeholder="Try 'Bret' or 'Delphine'"/> | |
<button>Search</button> | |
</form> | |
</div> | |
<div> | |
{ results.isPending ? | |
<div>Searching...</div> | |
: | |
results.data.map(({ data }) => | |
<div key={ data.id }>{ data.name }</div> | |
)} | |
</div> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment