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 - focus is not a function when getRenderedComponent

See original GitHub issue

Here is my code:

componentDidMount = () => {
    console.log(this.refs.lastName.getRenderedComponent());
    this.refs.lastName.getRenderedComponent().focus();

}

render() {
    return (
        <Grid containerStyle={{backgroundColor: '#fff'}}>
            
            <Row size={3.5} containerStyle={styles.topContainer}>
                <View>
                    <Field type="text" returnKeyType={"next"} ref="firstName" withRef
                           name="firstName" label="First Name" component={RenderField}/>

                    <Field last type="text" name="lastName" label="Last Name"
                           ref="lastName" withRef component={RenderField}/>

                </View>
            </Row>

        </Grid>
    )
}

 // Render Field

import React from 'react';
import PropTypes from 'prop-types';
import {Text} from 'react-native';
import {Item, Input, Label} from 'native-base';

class RenderField extends React.Component {
    render() {
        const {input, label, type, meta: {touched, error, invalid, warning}, custom} = this.props;

        let hasError = false;
        if (error !== undefined) {
            hasError = true;
        }
        return (
            <Item floatingLabel error={hasError} style={{marginBottom: 20}}>
                <Label>{label}</Label>
                <Input {...input} {...custom}/>
                {hasError ? <Text>{error}</Text> : <Text />}
            </Item>
        )
    }
}

export default RenderField;

The console.log return properly but at this.refs.lastName.getRenderedComponent().focus(); it always return this error _this.refs.lastName.getRenderedComponent().focus is not a function.

I’m using Redux Form v6 and Native Base v2

Thanks.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
dittmarconsultingcommented, May 13, 2017
2reactions
nschurmanncommented, Aug 9, 2017

Does not work with native base

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native - focus is not a function when ... - GitHub
Here is my code: componentDidMount = () => { console.log(this.refs.lastName.getRenderedComponent()); this.refs.lastName.
Read more >
React Native - Redux Form focus is not a function
getRenderedComponent ().focus is not a function . How can I set focus on specific input text? I'm using Redux Form v6 and Native...
Read more >
Call a function when focused screen changes | React Navigation
The hook will return true when the screen is focused and false when our component is no longer focused. This enables us to...
Read more >
Field - Redux Form
A function to call when the form field loses focus. It expects to either receive the React SyntheticEvent _or_ the current value of...
Read more >
TextInput - React Native
A foundational component for inputting text into the app via a keyboard. Props provide configurability for several features, ...
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