Module: "normalizeNestedObjects"

May 22, 2020 · View on GitHub

react-uniformed"normalizeNestedObjects"

Module: "normalizeNestedObjects"

Index

Functions

Functions

normalizeNestedObjects

normalizeNestedObjects(): NormalizerHandler

Used to add nested object support to useFields or useForms. Nested objects must use bracket notation. E.g. referencing an array value indexed at 0 would look like this arrayName[0]; referencing an object value that is keyed by 'country' would look like this locations[country].

example Basic mapping

   // jsx
   <input name="users[0]" value="John">
   // field value
   {users: ["John"]}

   // jsx
   <input name="users[0][name]" value="John">
   // field value
   {users: [{
       name: "John"
   }]}

   // jsx
   <input name="user['string keys with spaces']" value="John">
   // field value
   {user: {"string keys with spaces": "John"}}

example Usage with useForm and useFields

const {values} = useFields(
  {}, // initialValues must come first
  normalizeNestedObjects()
);

const {values} = useForm({
  normalizer: normalizeNestedObjects()
});

Returns: NormalizerHandler

Returns a normalizer handler