GeekyAnts / react-native-seed

Get your favorite boilerplate of React Native
http://ReactNativeSeed.com
652 stars 15 forks source link

Any easier way to access form data in LoginContainer login() function? #19

Closed ksangabriel closed 5 years ago

ksangabriel commented 5 years ago

Hi,

I am evaluating a codebase generated from react-native-seed. I looked at the samples in https://github.com/erikras/redux-form mentioned in https://github.com/GeekyAnts/react-native-seed/issues/4 but couldn't access the email and password in the form.

I get "Error: Field must be inside a component decorated with reduxForm()".

Any easier way to access the form data?

My sample codes: https://github.com/ksangabriel/react-native-eval/blob/master/LoginContainer_index.tsx

ksangabriel commented 5 years ago

I think I figured it out.

I added the email and password properties in Props interface.

...
export interface Props {
    navigation: any;
    valid: boolean;
    email: string;
    password: string;
}
...

Then, at the bottom, I now have:

...
const LoginContainer = reduxForm({
    form: "login",
})(LoginForm);

const selector = formValueSelector('login'); 

const mapStateToProps = state => ({
    email:  selector(state, 'email'),
    password: selector(state, 'password')
});

export default connect(mapStateToProps)(LoginContainer);

With these, I can retrieve email and password by:

this.props.email

this.props.password