Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import SearchBarNativeComponent, {
import { DirectEventHandler } from 'react-native/Libraries/Types/CodegenTypes';

const NativeSearchBar: React.ComponentType<
SearchBarNativeProps & { ref?: React.RefObject<SearchBarCommands> }
SearchBarNativeProps & {
ref?: React.RefObject<SearchBarCommands | undefined>;
}
> &
typeof NativeSearchBarCommands =
SearchBarNativeComponent as unknown as React.ComponentType<SearchBarNativeProps> &
Expand All @@ -36,7 +38,7 @@ type SearchBarCommandsType = {
};

function SearchBar(props: SearchBarProps, ref: React.Ref<SearchBarCommands>) {
const searchBarRef = React.useRef<SearchBarCommands | null>(null);
const searchBarRef = React.useRef<SearchBarCommands>(undefined);

React.useImperativeHandle(ref, () => ({
blur: () => {
Expand Down
2 changes: 1 addition & 1 deletion src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ export interface SearchBarProps {
* * `cancelSearch` - cancel search in search bar.
* * `toggleCancelButton` - depending on passed boolean value, hides or shows cancel button (iOS only)
*/
ref?: React.RefObject<SearchBarCommands>;
ref?: React.RefObject<SearchBarCommands | undefined>;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should really use React.Ref<SearchBarCommands>, which takes care of all the different shapes of react ref that could be passed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this or mine are both good,the actually used for me is wrong!


/**
* The auto-capitalization behavior
Expand Down