import React, { useState } from 'react'; import { nanoid } from 'nanoid'; import { IconTrash } from '@tabler/icons'; import StyledWrapper from './StyledWrapper'; const initialState = [{ uid: nanoid(), enabled: true }]; const RequestHeaders = () => { const [headers, setHeaders] = useState(initialState); const addHeader = () => { let newHeader = { uid: nanoid(), key: '', value: '', description: '', enabled: true }; let newHeaders = [...headers, newHeader]; setHeaders(newHeaders); }; const handleHeaderValueChange = (e, index, menu) => { // todo: yet to implement }; const handleRemoveHeader = (index) => { headers.splice(index, 1); setHeaders([...headers]); }; return ( {headers && headers.length ? headers.map((header, index) => { return ( ); }) : null}
Key Value Description
handleHeaderValueChange(e, index, 'key')} /> handleHeaderValueChange(e, index, 'value')} /> handleHeaderValueChange(e, index, 'description')} />
handleHeaderValueChange(e, index, 'enabled')} />
) }; export default RequestHeaders;