byteburgers / react-native-autocomplete-input

Pure javascript autocomplete input for react-native
https://byteburgers.com/autocomplete
MIT License
805 stars 255 forks source link

adding ref for text input #220

Closed mhendyl closed 2 years ago

mhendyl commented 2 years ago

please approve this merge i need this ref prop for textinput

cavishek39 commented 2 years ago

@Lg0gs @Thanhal-P-A can you guys approve the PR, it's a very important feature?

mrlaessig commented 2 years ago

Try to implement it like this. There shouldn't be the need to introduce a new prop.

function SomeComponent() {
  const inputEl = useRef(null);
  return (
    <Autocomplete
      // ...
      renderTextInput={(props) => <TextInput {...props} ref={inputEl} />}
    />
  )
}
cavishek39 commented 2 years ago

<TextInput {...props} ref={inputEl} />

@mrlaessig thanks buddy, but still I feel this approach will be good if we use this package as a wrapper, but for someone who is directly using this package everywhere in their codebase, it'll not be ideal to refactor it everywhere. Anyway till the time there is a permanent solution or a prop is available we can go on like this.

mrlaessig commented 2 years ago

Resolved within #243. Now you can set the ref prop in the autocomplete to get a reference to the text input.