{"action":"created","issue":{"url":"https://api.github.com/repos/FaridSafi/react-native-gifted-chat/issues/777","repository_url":"https://api.github.com/repos/FaridSafi/react-native-gifted-chat","labels_url":"https://api.github.com/repos/FaridSafi/react-native-gifted-chat/issues/777/labels{/name}","comments_url":"https://api.github.com/repos/FaridSafi/react-native-gifted-chat/issues/777/comments","events_url":"https://api.github.com/repos/FaridSafi/react-native-gifted-chat/issues/777/events","html_url":"https://github.com/FaridSafi/react-native-gifted-chat/issues/777","id":301514160,"number":777,"title":"How to prevent the text input to be cleared if the onSend() function fails?","user":{"login":"gianpaj","id":899175,"avatar_url":"https://avatars3.githubusercontent.com/u/899175?v=4","gravatar_id":"","url":"https://api.github.com/users/gianpaj","html_url":"https://github.com/gianpaj","followers_url":"https://api.github.com/users/gianpaj/followers","following_url":"https://api.github.com/users/gianpaj/following{/other_user}","gists_url":"https://api.github.com/users/gianpaj/gists{/gist_id}","starred_url":"https://api.github.com/users/gianpaj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gianpaj/subscriptions","organizations_url":"https://api.github.com/users/gianpaj/orgs","repos_url":"https://api.github.com/users/gianpaj/repos","events_url":"https://api.github.com/users/gianpaj/events{/privacy}","received_events_url":"https://api.github.com/users/gianpaj/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-03-01T18:39:14Z","updated_at":"2018-05-29T20:15:39Z","closed_at":null,"author_association":"NONE","body":"#### Issue Description\r\n\r\nThe `onSend(messages)` function doesn't seem to have a callback, so if the app, for example, cannot connect to the backend the input field text will be cleared no matter if it succeeds or not.\r\n\r\nFor example, the device is offline, I would like to show an error and allow to retry once it's connected again.\r\n\r\nThanks\r\n\r\n#### Expected Results\r\n\r\nThe `onSend()` to have a callback to handle this.\r\n\r\n#### Additional Information\r\n\r\n* react-native-gifted-chat version: ^0.3.0\r\n"},"comment":{"url":"https://api.github.com/repos/FaridSafi/react-native-gifted-chat/issues/comments/392928703","html_url":"https://github.com/FaridSafi/react-native-gifted-chat/issues/777#issuecomment-392928703","issue_url":"https://api.github.com/repos/FaridSafi/react-native-gifted-chat/issues/777","id":392928703,"user":{"login":"ewal","id":676873,"avatar_url":"https://avatars1.githubusercontent.com/u/676873?v=4","gravatar_id":"","url":"https://api.github.com/users/ewal","html_url":"https://github.com/ewal","followers_url":"https://api.github.com/users/ewal/followers","following_url":"https://api.github.com/users/ewal/following{/other_user}","gists_url":"https://api.github.com/users/ewal/gists{/gist_id}","starred_url":"https://api.github.com/users/ewal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ewal/subscriptions","organizations_url":"https://api.github.com/users/ewal/orgs","repos_url":"https://api.github.com/users/ewal/repos","events_url":"https://api.github.com/users/ewal/events{/privacy}","received_events_url":"https://api.github.com/users/ewal/received_events","type":"User","site_admin":false},"created_at":"2018-05-29T20:15:39Z","updated_at":"2018-05-29T20:15:39Z","author_association":"NONE","body":"@gianpaj, I just figured it out. Bind the function to a property function in your component class like such:\r\n```javascript\r\nclass Chat extends Component {\r\n  ...\r\n  handleOnSend = messages => (\r\n    CallSomeApiEndpoint(messages[0].text); // Or get the text from the state\r\n  );\r\n  ...\r\n  render() {\r\n    return (\r\n      <GiftedChat\r\n        ...\r\n        text={this.state.text}\r\n        onInputTextChanged={text => this.setState({ text })}\r\n        ...\r\n        // Working\r\n        onSend={this.handleOnSend}\r\n\r\n        // NOT working\r\n        onSend={messages =>\r\n          CallSomeApiEndpoint(messages[0].text);\r\n        }\r\n       ...\r\n      />\r\n    );\r\n  }\r\n}\r\n```\r\n\r\nI use Redux for managing the state, but I guess the above will work. Otherwise, try Redux :) "}}
{"actor":{"display_login":"ewal"}}