Add Object.fromEntries() ponyfill

This commit is contained in:
divlo
2020-08-05 02:53:04 +02:00
parent 25aa143110
commit c577509e6f
5 changed files with 108 additions and 45 deletions

9
src/fromEntries.ts Normal file
View File

@ -0,0 +1,9 @@
/*! fromentries. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
export function fromEntries<T = any> (
iterable: Iterable<readonly [PropertyKey, T]>
) {
return [...iterable].reduce((object, [key, value]) => {
object[key] = value
return object
}, {})
}

View File

@ -1,4 +1,5 @@
import React, { useRef } from 'react'
import { fromEntries } from './fromEntries'
export interface FormDataObject {
[key: string]: FormDataEntryValue
@ -20,7 +21,7 @@ interface FormProps extends ReactFormProps {
}
const getFormDataObject = (formElement: HTMLFormElement): FormDataObject => {
return Object.fromEntries<FormDataEntryValue>(new FormData(formElement))
return fromEntries<FormDataEntryValue>(new FormData(formElement))
}
const Form = (props: FormProps): JSX.Element => {