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.

Uncaught TypeError: Cannot read property 'focus' of undefined

See original GitHub issue

I met error when I use renderInputComponent API.

autosuggest.js:698 Uncaught TypeError: Cannot read property 'focus' of undefined
    at Object.onSuggestionClick [as onClick] (autosuggest.js:698)
    at Item._this.onClick (autosuggest.js:2941)
    at Object.ReactErrorUtils.invokeGuardedCallback (react-dom.js:9017)
    at executeDispatch (react-dom.js:3006)
    at Object.executeDispatchesInOrder (react-dom.js:3029)
    at executeDispatchesAndRelease (react-dom.js:2431)
    at executeDispatchesAndReleaseTopLevel (react-dom.js:2442)
    at Array.forEach (<anonymous>)
    at forEachAccumulated (react-dom.js:15423)
    at Object.processEventQueue (react-dom.js:2645)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:15

github_iconTop GitHub Comments

2reactions
cameronblandfordcommented, Nov 23, 2020

I got this error, but wasn’t using any external library for the input.

What fixed it for me was adding focusInputOnSuggestionClick={false} to the AutoSuggest props. Seems like it’s enabled by default and the component lost track of its own ref and errored out.

1reaction
bdmasoncommented, Aug 13, 2019

renderInputComponent receives a ref in the component, this needs to be attached to your input component. I’m using MUI and this solves it:

const renderInputComponent = inputProps => {
  const { error, label, ref, ...rest } = inputProps

  return (
    <TextField
      error={!!error}
      label={label}
      fullWidth
      InputProps={{
        inputRef: node => {
          ref(node)
        },
      }}
      {...rest}
    />
  )
}

You can do this if you’re using a basic HTML input tag:

<input ref={ref} />
Read more comments on GitHub >

github_iconTop Results From Across the Web

"Uncaught TypeError: Cannot read property 'focus' of null ...
javascript - Receiving Error Message: "Uncaught TypeError: Cannot read property 'focus' of null" when trying to call focus() to an element ID - ......
Read more >
Cannot read property 'focus' of Null in JavaScript | bobbyhadz
The "Cannot read property 'focus' of null" error occurs when trying to call the focus() method on a null value. To solve the...
Read more >
JavaScript error: Cannot read property "focus" of null
I have an issue when applying this Javascript to focus an input. This error appears to me. I have this JavaScript and when...
Read more >
Cannot read property 'focus' of null : RG-2080 - YouTrack
main.e88435a8acec14a47dcb.js:28 Uncaught TypeError: Cannot read property 'focus' of null. 1. Is required for 1 Is duplicated by 2.
Read more >
Uncaught TypeError: Cannot read property 'focus' of null
Alternatively to be double sure about id can you write a line that alert(document.getElementById(id)); inside your javascript. This should not ...
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