
6

Single react-native hook to manage auto focus of TextInput
source link: https://reactnativeexample.com/single-react-native-hook-to-manage-auto-focus-of-textinput/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

use-auto-focus-inputs
Single react-native hook to manage auto focus of TextInput
Check out example project on expo snack.
Features
- One, headless hook
- Written with Typescipt
- Integration with UI libraries
- No extra dependencies
Install
npm install use-auto-focus-inputs
Quickstart
import * as React from 'react';
import {TextInput, View} from 'react-native';
import useAutoFocusInputs from 'use-auto-focus-inputs';
function App() {
const [firstName, setFirstName] = React.useState('');
const [lastName, setLastName] = React.useState('');
const [email, setEmail] = React.useState('');
const getAutoFocusableInputProps = useAutoFocusInputs();
return (
<View style={{flex: 1}}>
<TextInput
{...getAutoFocusableInputProps({
placeholder: 'first name',
value: firstName,
onChangeText: setFirstName,
style: {width: '100%'},
})}
/>
<TextInput
{...getAutoFocusableInputProps({
placeholder: 'last name',
value: lastName,
onChangeText: setLastName,
style: {width: '100%'},
})}
/>
<TextInput
{...getAutoFocusableInputProps({
placeholder: 'email',
value: email,
onChangeText: setEmail,
style: {width: '100%'},
})}
/>
</View>
);
}
React JSX
Contribution
Suggestions and PR-s are welcome!
GitHub
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK