0

I have a login form component with the following state:

  constructor(props) {
    super(props);

    this.state = { email: '', password: '', error: '' };

    this.handleOnPress = this.handleOnPress.bind(this);
  }

handleOnPress simply logs this.state.email, like so:

  handleOnPress() {
    const { email, password } = this.state;

    console.log(email);
  }

I have a custom Input component:

  <Input
    value={this.state.email}
    placeholder="[email protected]"
    onChange={email => this.setState({ email })}
    label="Email"
  />

Defined like so:

  <TextInput
    style={styles.input}
    value={value}
    onChange={onChange}
    placeholder={placeholder}
    autoCorrect={autoCorrect}
    secureTextEntry={secureTextEntry}
  />

So when tap the button, this is what is logged in the console:

Proxy {dispatchConfig: {…}, _targetInst: FiberNode, isDefaultPrevented: ƒ, isPropagationStopped: ƒ, _dispatchListeners: null, …}

Shouldn't the value of the input field be logged, instead of the above object? What am I doing wrong?

2 Answers 2

1

Looks like I was using the wrong prop. Should have been onChangeText instead of onChange, as onChangeText accepts an argument to the callback.

Sign up to request clarification or add additional context in comments.

Comments

1

you need to do this

onChange={event => this.setState({ email:event.target.value })}

1 Comment

Thanks, but I prefer using onChangeText, slightly less code to write :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.