Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import React from 'react';
  2.  
  3. import Select from 'react-select';
  4.  
  5. // http://127.0.0.1:8001/api/categories?project_id=1
  6.  
  7. export default class CategoryList extends React.Component {
  8.  
  9. constructor(props) {
  10. super(props);
  11.  
  12. //this.onChange = this.onChange.bind(this);
  13. }
  14.  
  15. onChange(value) {
  16. console.log(value);
  17. //this.setState(state);
  18. this.setState({
  19. value: value,
  20. });
  21. }
  22.  
  23. getOptions(input) {
  24. return fetch(`/api/categories?project_id=1&${input}.json`)
  25. .then((response) => {
  26. return response.json();
  27. }).then((json) => {
  28. return { options: json };
  29. });
  30. }
  31.  
  32. render() {
  33. return (
  34. <Select.Async
  35. name="form-field-name"
  36. value="3"
  37. onChange={ this.onChange }
  38. loadOptions={this.getOptions}
  39. />
  40. );
  41. }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement