redux-form: [V6] I can't access to form props in react-native
I don’t understand how can I access to form props. I used formValueSelector
as suggested the documentation, but doesn’t work. Where is my mistake?
LoginForm.js
'use strict';
import React from 'react';
import { Field, reduxForm, formValueSelector } from 'redux-form';
import { TextInput, View, TouchableHighlight, Text } from 'react-native';
import { connect } from 'react-redux';
class LoginForm extends React.Component {
handeSubmit(email, password){ alert(`email: ${email} and password: ${password}`)};
render() {
return (
<View>
<Field
name="email"
component={TextInput}
placeholder="Email"
/>
<Field
name="password"
component={TextInput}
placeholder="Password"
secureTextEntry={true}
/>
<TouchableHighlight onPress={() => this.handeSubmit(this.props.email, this.props.password)}>
<Text>Submit</Text>
</TouchableHighlight>
</View>
);
}
}
LoginForm = reduxForm({
form: 'loginForm'
})(LoginForm);
const selector = formValueSelector('loginForm');
function mapStateToProps(state){
return {
email: selector(state, 'email'),
password: selector(state, 'password'),
}
}
LoginForm = connect(mapStateToProps)(LoginForm);
export default LoginForm;
LoginPage.js
'use strict';
import React from 'react';
import {View} from 'react-native';
import Container from '../../components/Container';
import LoginForm from '../../components/forms/LoginForm';
class LoginPage extends React.Component {
render() {
return (
<Container>
<LoginForm/>
</Container>
);
}
}
export default LoginPage;
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 23 (3 by maintainers)
I found the solution. TextInput doesn’t work with redux-form as it is. It need a component than pass the redux-form props like this:
Instead of import TextInput inside the forms, import the custom TextField.
I see most of are posting their solution regarding react native and redux form. I am posting either, thinking that my code might help other
Here is my working code with output
Sorry the design is terrible right now 😃
Thanks, Happy Coding
Wow, I was stuck on trying to use react-native with redux-form, and finally found this thread. Would be great to have a React Native example with this tip, thx!