react-hook-form#DeepMap TypeScript Examples

The following examples show how to use react-hook-form#DeepMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: handle-form-error.tsx    From admin with MIT License 7 votes vote down vote up
function getFormErrors(errors: DeepMap<FieldValues, FieldError>) {
  const messages: string[] = Object.values(errors).reduce(
    (acc, { message }) => {
      if (message) {
        acc.push(message)
      }

      return acc
    },
    []
  )

  const refs = Object.values(errors).reduce((acc, { ref }) => {
    if (ref) {
      acc.push(ref)
    }

    return acc
  }, [])

  const list = (
    <ul className="list-disc list-inside">
      {messages.map((m) => (
        <li>{m}</li>
      ))}
    </ul>
  )

  const title =
    messages.length > 1
      ? `There were ${messages.length} errors with your submission`
      : "There was an error with your submission"

  return { title, list, refs }
}
Example #2
Source File: form-helpers.ts    From admin with MIT License 6 votes vote down vote up
checkForDirtyState = (
  dirtyFields: DeepMap<Record<string, any>, true>,
  otherValues: Record<string, boolean>
) => {
  const otherDirtyState = otherValues
    ? Object.values(otherValues).some((v) => v)
    : false

  return !!Object.keys(dirtyFields).length || otherDirtyState
}
Example #3
Source File: util.ts    From UsTaxes with GNU Affero General Public License v3.0 6 votes vote down vote up
getNestedValue = <A, E, V>(
  obj: DeepMap<DeepPartial<A>, E>,
  path: string,
  defaultValue: V
): E | V => _.get(obj, path, defaultValue) as E | V