iusehooks / usetheform

React library for composing declarative forms, manage their state, handling their validation and much more.
https://iusehooks.github.io/usetheform/
MIT License
86 stars 33 forks source link

Fix initial value undefined issue when passed as prop for useField - … #26

Closed iusehooks closed 3 years ago

iusehooks commented 3 years ago

Improvement:

Example:

const CustomField = ({ name }) => {
  const { value } = useField({ type: "text", name, value: "5" });

  // Now, value it is defined since the first render => value = "5"
  // does not need to wait for the <Form /> to be READY

  return (
    <pre>
      <code data-testid="output">{JSON.stringify(value)}</code>
    </pre>
  );
};

function App() {
  return (
    <Form>
      <Input type="text" name="user" value="BeBo" />
      <CustomField name="other"  />
    </Form>
  );
}