State Management
Main things to know: managing state (locally or via a reducer) is basically identical to React for web. In fact, they both use the react library, so that shouldn't be surprising. I guess the react library is just a very generalizable way of representing and tracking changes to a UI.
TextInput
TextInputReact Native provides a primitive TextInput component for handling text inputs.
const InputScreen = () => {
const [text, setText] = useState('');
<TextInput
style={{ margin: 15, padding: 15, borderColor: 'black', borderWidth: 1 }}
value={text}
onChangeText={setText}
autoCapitalize='none'
autoCorrect={false}
/>;
};Things to note:
There are no default styles, so
TextInputwill appear invisible by default.Like any input in React, you're making it a controlled component. The only difference is that
onChangeTextis youronChangecallback, and it returns the new value of the input.On iOS by default, the first character in your input gets capitalized. To change this, you have the
autoCapitalizeprop.By default, words in your input get autocorrect recommendations. In cases where you don't want that (e.g. inputting a username), you have the
autoCorrectprop.
Last updated