Guest User

Untitled

a guest
Jul 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. function debounce (fn, time) {
  2. let timeoutId
  3. return wrapper
  4. function wrapper (...args) {
  5. if (timeoutId) {
  6. clearTimeout(timeoutId)
  7. }
  8. timeoutId = setTimeout(() => {
  9. timeoutId = null
  10. fn(...args)
  11. }, time)
  12. }
  13. }
  14.  
  15. class SearchMedicine extends React.Component {
  16. constructor (props) {
  17. super(props)
  18. this.searchMedicineOnChange = this.searchMedicineOnChange.bind(this)
  19. }
  20.  
  21. searchMedicineOnChange = debounce(value => {
  22. if (value.length > 3) {
  23. this.props.searchMedicineLoading(
  24. this.props.searchMedicineState,
  25. this.props.checkPincodeState.payload.id,
  26. value
  27. )
  28. }
  29. }, 1000)
  30.  
  31. render() {
  32. return (
  33. <input onChange={this.searchMedicineOnChange} />
  34. )
  35. }
Add Comment
Please, Sign In to add comment