Lecture # 17 - React Native Form Handling: by Dr. Sidra Sultana
Lecture # 17 - React Native Form Handling: by Dr. Sidra Sultana
Handling
By Dr. Sidra Sultana
Scaffolding Project
We start by creating an blank Expo project.
expo init
From within the new project folder, install the additional
dependencies.
yarn add prop-types
yarn add redux
yarn add react-redux
yarn add redux-form
At this point, we can start the application.
expo start
App.js
import { Provider } from 'react-redux';
import { createStore, combineReducers } from 'redux';
import { reducer as formReducer } from 'redux-form';
render() {
return <HelloFormRF onSubmit={this.handleSubmit} />;
}
}
<View>
<Button
title="Submit Hello"
onPress={handleSubmit}
/>
</View>
);
HelloFormView.propTypes = {
handleSubmit: PropTypes.func.isRequired,
};
<TextInput
onChangeText={onChange}
value={value}
style={styles.root}
/>
);
RFTextInput.propTypes = {
input: PropTypes.shape({
onChange: PropTypes.func.isRequired,
value: PropTypes.string.isRequired,
}).isRequired,
}
export default RFTextInput;
Observations:
The RFTextInput component translates the supplied
(by Redux
Form) input.onChange and input.value properties to
the onChangeText and value properties used by the React
Native TextInput component
In order to better see the TextInput component, we apply
minimal styling through an external style sheet; good
practice is to separate the styles (can be complex) from the
view component
components / RFTextInput / styles.js
SimpleFormView.propTypes = {
handleSubmit: PropTypes.func.isRequired,
};