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.

"dispatchCommand was called with a ref that isn't a native component" in searchbar while focusing using ref

See original GitHub issue

Current behaviour

Warning: dispatchCommand was called with a ref that isn’t a native component. Use React.forwardRef to get access to the underlying native component

This warning is appearing while using searchbar component ref while using focus() method

Expected behaviour

It should focus the searchbar input

Stack trace:

Warning: dispatchCommand was called with a ref that isn’t a native component. Use React.forwardRef to get access to the underlying native component

  • node_modules\react-native\Libraries\LogBox\LogBox.js:173:8 in registerError
  • node_modules\react-native\Libraries\LogBox\LogBox.js:59:8 in errorImpl
  • node_modules\react-native\Libraries\LogBox\LogBox.js:33:4 in console.error
  • node_modules\expo\build\environment\react-native-logs.fx.js:27:4 in error
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:106:4 in printWarning
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:75:16 in error
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:21034:11 in dispatchCommand- node_modules\react-native\Libraries\Utilities\codegenNativeCommands.js:24:6 in commandObj.command
  • node_modules\react-native\Libraries\Components\TextInput\TextInputState.js:99:6 in focusTextInput
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:3871:6 in focus
  • node_modules\react-native\Libraries\Interaction\TaskQueue.js:117:14 in processNext
  • node_modules\react-native\Libraries\Interaction\InteractionManager.js:207:6 in _processUpdate
  • node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer
  • node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14 in _callImmediatesPass
  • node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 in callImmediates
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6 in __callImmediates
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6 in __guard$argument_0
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 in flushedQueue
  • [native code]:null in flushedQueue
  • [native code]:null in callFunctionReturnFlushedQueue

Code sample

`import React, { useRef, useState } from “react”; import { Modal, SafeAreaView, StyleSheet, View} from “react-native”; import { IconButton, Searchbar } from “react-native-paper”; // import colors from “…/assets/config/colors”;

const SearchModal = ({ visible, onClose }) => {

const [searchQuery, setSearchQuery] = useState('')
const searchFieldRef = useRef()

const onChangeText = (t) => setSearchQuery(t)

const handleShow = () => {
    searchFieldRef.current.focus()
}

return (
    <Modal visible={visible} onShow={handleShow} animationType="slide">
        <SafeAreaView>
            <View style={styles.header}>
                <IconButton
                    icon="arrow-left"
                    onPress={onClose}
                />
                <Searchbar style={styles.searchbar} 
                    inputStyle={styles.searchbarInput}
                    value={searchQuery}
                    placeholder="Find People"
                    onChangeText={onChangeText}
                    ref={searchFieldRef}
                />
            </View>
        </SafeAreaView>
    </Modal>
);

};

export default SearchModal;

const styles = StyleSheet.create({ header: { flexDirection: “row”, alignItems: “center” },

searchbar:{
    height: 40,
    marginRight: 6,
    elevation: 0,
    flex: 1,
    // backgroundColor: colors.bg
    backgroundColor: "yellow"
  },

  searchbarInput:{
    fontSize: 15
  }

}); `

What have you tried

  • autoFocus not working on modal (android)

Your Environment

software version
android 10
react-native-paper 4.4.1
node 14.12.0
npm 6.14.9
expo sdk 39.0.2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:6

github_iconTop GitHub Comments

5reactions
karimcambridgecommented, Dec 30, 2020

ref doesn’t seem to work with Searchbar anymore since some version 4.x.x something, I can confirm. Can someone help us?

4reactions
YahyaBagiacommented, Jan 18, 2021

Having same issue on v4.7.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-native elements search bar ref to use focus() method for ...
I think I found the issue. As my SearchScreen is part of a TabBar from react-navigation, this.search.focus() error was appearing at the ...
Read more >
Refs in React - Pragim Tech
With in this function, we will call the focus method using the reference which is being passed. Now lets call this function component...
Read more >
How to Use Browser Event Listeners in React for Search and ...
For finding direct access to DOM nodes, we can take advantage of refs that let us use APIs native to the browser right...
Read more >
SearchBar - React Native Elements
SearchBar. SearchBars are used to search or filter items. Use a SearchBar when the number of items directly impacts a user's ability to...
Read more >
mozilla-central: changeset 384049 ...
This allows the commandbar to remain fixed when scrolling until the content completely ends. Not just the height of the wrapper. Ref: ...
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