0.1.4 • Published 3 years ago
use-auto-focus-inputs v0.1.4
use-auto-focus-inputs
Demo
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-inputsQuickstart
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>
  );
}Contribution
Suggestions and PR-s are welcome!