@comparaonline/ui-input-listener

The input listener actually renders a Field component from react-final-form with the same input name that the field that we want to change and uses the onChange function to update its value.

Usage no npm install needed!

<script type="module">
  import comparaonlineUiInputListener from 'https://cdn.skypack.dev/@comparaonline/ui-input-listener';
</script>

README

Input Listener

Usage

The input listener actually renders a Field component from react-final-form with the same input name that the field that we want to change and uses the onChange function to update its value.

import { Form } from 'react-final-form';
import { TextField } from '@comparaonline/ui-form-fields';
import { InputListener } from '@comparaonline/ui-input-listener';

const onSubmit = () => undefined;

<Form onSubmit={onSubmit}>
  {({ handleSubmit }) => (
    <form onSubmit={handleSubmit}>
      <TextField
        name="inputA"
        label="Placa"
      />
      <TextField
        name="inputB"
        label="Placa"
      />
      <InputListener field="inputA" when={value => value === 'foo'} set="inputB" to={new Promise(resolve => resolve('new value'))} />
    </form>}
</Form>;