✨ Add Object.fromEntries() ponyfill
This commit is contained in:
9
src/fromEntries.ts
Normal file
9
src/fromEntries.ts
Normal 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
|
||||
}, {})
|
||||
}
|
@ -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 => {
|
||||
|
Reference in New Issue
Block a user