Skip to content

TextInput ignoring passed in value #28815

Closed
@DChen7

Description

@DChen7

Please provide all the information requested. Issues that do not follow this format are likely to stall.

Description

TextInput component shows different value than what is passed in through the value prop
Screen Shot 2020-05-02 at 11 04 34 PM
Screen Shot 2020-05-02 at 11 04 51 PM

React Native version:

0.62.0

Steps To Reproduce

  1. Type '2' into input
  2. Type 'f' into input twice

Expected Results

Expected to only see integers in the text input

Snack, code example, screenshot, or link to a repository:

  const onChange = (value: string) => {
    const trimmed = value.replace(/\D/g,'');
    props.onChange(trimmed.substring(0, Math.min(trimmed.length, props.maxDigits)));
  }
  console.log('props.value', props.value)
  return (
    <TextInput
      onChangeText={onChange}
      value={props.value}
    />
);

passed in onChange function is just onChangeWeight:

const [weight, setWeight] = useState('');
  const onChangeWeight = (w: string) => {
    return setWeight(w);
  };

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: TextInputRelated to the TextInput component.Needs: Triage 🔍StaleThere has been a lack of activity on this issue and it may be closed soon.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions