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.

[react-native] Button props - Cannot read property activeElement of undefined

See original GitHub issue
  • downshift version: 1.28.0
  • node version: 8.5.0
  • npm (or yarn) version: 5.6.0
  • react-native version: 0.52.0
  • react version: 16.2.0

Relevant code or config

What you did: Hey! tried to use the new and experimental react-native version (Thanks for that!), With Button instead of TextInput as the trigger.

What happened: Cannot read property activeElement of undefined error has thrown. screen shot 2018-02-19 at 15 59 24

Reproduction repository: https://github.com/eyalcohen4/downshift-react-native-bug

Problem description: I think its related to the access attempt for document property of environment object, while it’s missing on react-native when I print environment.

Suggested solution: Check if we are in react-native env using isReactNative before this condition - if ( !isReactNative() && this.props.environment.document.activeElement === this.props.environment.document.body ) { event.target.focus() }

Will be happy to make a PR if it looks like the right solution. cc @kentcdodds @eliperkins

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:22 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
kentcdoddscommented, Mar 30, 2018

TREVOR!!! I miss you already buddy!

This is great. I don’t think you’re doing anything wrong. If you could dig a little further to see what’s going on then we can get that error fixed.

As for an example, I’m not very into the react native world, but I think that a snack.expo.io link would be sweet 😃

1reaction
trevorwhealycommented, Mar 30, 2018

Copied the axios example (http://downshift.netlify.com/?selectedKind=Examples&selectedStory=axios&full=0&addons=1&stories=1&panelRight=0), and found the port over to React Native to be pretty easy, but was surprised that any dropdown item I click (or anywhere I click) triggers this ActiveElement error.

Not sure what I’m doing wrong, but happy to add my basic example to the docs, because I don’t see any simple starter for a basic working setup with RN. Guessing it has to do with the ref like you mentioned above, but as far as I can tell, I’m doing everything the suggested way.

import React, { Component } from 'react';
import { TextInput, View, Text, Image } from 'react-native';

import axios from 'axios';
import Downshift from 'downshift';

const CustomInput = TextInput;
const CustomResult = View;

const RootView = ({ innerRef, ...rest }) => <View ref={innerRef} {...rest} />;

class AxiosAutocomplete extends Component {
  this.state = { items: [] };

  fetchRepository = axios.get().then(this.setState({ items }))

  render() {
    return (
      <Downshift
        render={({
          getInputProps,
          getItemProps,
          isOpen,
          getRootProps,
        }) => (
          <RootView {...getRootProps({ refKey: 'innerRef' })}>
            <CustomInput
              {...getInputProps({
                onChange: (value) => {
                  this.fetchRepository(value);
                },
              })}
            />
            {isOpen && (
              <View>
                {this.state.items.map((item, index) => (
                  <CustomResult key={index} {...getItemProps({ item })}>
                      {item}
                  </CustomResult>
                ))}
              </View>
            )}
          </RootView>
        )}
      />
    );
  }
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

React - TypeError: Cannot read property 'props' of undefined
Bind this to all functions (in the constructor) ; class Character ; extends Component ; constructor(props) ; super(props) this ; handleDelete = this ......
Read more >
3 ways to autofocus an input in React that ALMOST always work!
Deep dive into the autofocus attribute, the focus() method, the autoFocus prop, the useRef hook and callback refs.
Read more >
Initializing focus state in React: you might be doing it wrong
So, when our component first mounts, we need to check whether it was already focused. To check whether an element is focused in...
Read more >
js find active element Code Example - Code Grepper
What is the use of the return function in the React Native Framework? ... cannot read property of undefined (reading 'push') react ...
Read more >
Check if an Element is focused in React | bobbyhadz
To check if an element is focused in React, set the `ref` prop on the element. After the element is rendered, check if...
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