React Native - focus is not a function when getRenderedComponent
See original GitHub issueHere 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:
- Created 6 years ago
- Reactions:1
- Comments:9 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found a solution @stefensuhat. I posted it on StackOverflow http://stackoverflow.com/questions/43917795/react-native-redux-form-use-keyboard-next-button-to-go-to-next-textinput-fie/43952870#43952870
Please up-vote if this was helpful
Does not work with native base