import React from 'react' /** * * @param { [ {}, {}, ...{} ] } inputList - list of dicts with info about input * @param { [] } refList - react ref objects list for handler validation * @param { } action - fetch method */ export const FormGenerator = ({ inputList, refList, action }) => { const handler = async (event) => { event.preventDefault() for ( let i = 0; i < refList.length; i++ ) { if ( refList[i].current.value === '' && inputList[0].action !== 'Update' || i === 0 && refList.length !== 1 ) { refList[i].current.focus() } else if ( i === refList.length - 1 ) { await action( refList ) } } } let info return (
handler( event ) }> { inputList.map( (input, key) => { if ( input.type === 'info' ) { info = input } else if ( input.type === 'text' ) { return ( ) } else if ( input.type === 'file' ) { return ( ) } }) }