SearchBar typescript props missing
See original GitHub issueI 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:
searchFieldRef.current?.blur();
- it doesn’t know about blur.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:
- Created 3 years ago
- Reactions:8
- Comments:13 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
We have now lost the
onChangeText
prop, so this change has introduced a breaking change