GeekyAnts / react-native-seed

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

how to access form data in LoginContainer login() function? #4

Closed Talor-A closed 6 years ago

Talor-A commented 6 years ago

hi, how can I get the login data (email and password) and use it in the login function to login with my server?

shivrajkumar commented 6 years ago

@Talor-A The data should be available with loginForm i.e, this.props.loginForm.email.

Talor-A commented 6 years ago

ah ok. is there any particular reason the form isn't using the redux-form onSubmit prop?

shivrajkumar commented 6 years ago

@Talor-A The Form component being used there is NativeBase component. onSubmit prop is not available to it. And we also wanted to add a Toast to show the error message for the form.

Talor-A commented 6 years ago

@shivrajkumar so to access email and password inside LoginContainer login() method I could put

const form = (
      <Form>
      ...
      </Form>
  )
return <Login loginForm={form} onLogin={() => this.login(form)} />

in my render() method? and then in login() method:

  login = (form) => {
    console.warn(`Email: ${form.email}, Password: ${form.password}`)
    ...
  }

is this correct? I'm getting email and password undefined in the console.warn statement.

shivrajkumar commented 6 years ago

@Talor-A email and password data is not available with redux form example here. I was talking about mobX and MST variation. Sorry about the confusion. You can get the values using onChange function on Input and use them as needed. Check https://github.com/erikras/redux-form for further details.