question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SearchBar typescript props missing

See original GitHub issue

I import SearchBar and need to create a ref for it:

import { SearchBar, SearchBarProps } from 'react-native-elements';
const searchFieldRef = useRef<SearchBarProps>(null);
const blurSearch = useCallback(() => {
   searchFieldRef.current?.blur();
  }, [searchFieldRef]);

<SearchBar ref={searchFieldRef} onPress={blurSearch} ...

I get a typescript error on:

  1. searchFieldRef.current?.blur(); - it doesn’t know about blur.
  2. ref={searchFieldRef} on the SearchField itself

The first issue I can, in an ugly way, fix by adding the methods to the typescript definition like so:

type MissingProps = {
  focus: () => void;
  blur: () => void;
  clear: () => void;
  cancel: () => void;
}
const searchFieldRef = useRef<SearchBarProps & MissingProps>(null);

I prefer this to be handled correctly of course. But one thing I am not sure how to fix is ref={searchFieldRef}

Could you please advise how to properly import the typescript definition of this component? Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
khushal87commented, Mar 22, 2021

There are other issues with the SearchBar types, too. For example, the docs say I can use placeholder, for example, but I’m getting a warning that it’s not a valid prop. Looking through the types shipped, it looks like this is missing.

The codebase only just transitioned to TypeScript so I’m guessing it’s just a small bug that got through and one that’ll be fixed soon. The same for your case, too.

I have raised the PR for the same https://github.com/react-native-elements/react-native-elements/pull/2892 this will be solved soon. Thank you.

6reactions
tidusjarcommented, Apr 27, 2021

We have now lost the onChangeText prop, so this change has introduced a breaking change

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - SearchBar typescript props missing - - Bountysource
I import SearchBar and need to create a ref for it: import { SearchBar, SearchBarProps } from 'react-native-elements'; const searchFieldRef ...
Read more >
Property 'value' is missing in type '{ searchValue: string ...
But when I try to render the search bar on my app I get this error: Property 'value' is missing in type '{...
Read more >
Customs search box - exposed props missing in TS?
Hey! I'm trying to make a custom search box, but can't seem to pass the custom Algolia props. The docs state that I...
Read more >
Search Bar in React featuring Typescript and Redux | by Roza J
We can see from the below code that they are passed as arguments. class App extends React.Component<Props, State> { constructor(props: Props) {
Read more >
material-ui-search-bar - npm
This allows for much flexibility, e.g. you can change and clear the search input just by changing its props. import SearchBar from " ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found