Skip to content

Instantly share code, notes, and snippets.

@arifshariati
Created June 20, 2021 07:34
Show Gist options
  • Save arifshariati/c607a2baf87976f8a2a2ce61c988db4f to your computer and use it in GitHub Desktop.
Save arifshariati/c607a2baf87976f8a2a2ce61c988db4f to your computer and use it in GitHub Desktop.
React Form Dynamic Rendering
import React from 'react';
import { TextField, IconButton, Divider, InputField } from '../components';
import { BiUpload } from 'react-icons/bi';
const RenderFormFields = ({id, type, label}) => {
const handleFileUpload = () => {
document.getElementById("fileupload").click();
};
switch(type) {
case "InputField": return (<InputField />);
case "FileUpload": return(
<IconButton onClick={handleFileUpload}>
<BiUpload fontSize="large" />
<h3>{label}</h3>
<input id="fileupload" type="file" style={{display:'none'}} />
</IconButton>
);
case "Divider": return (
<Divider id={id} />
);
default: return(<TextField type= {type} label= {label} id={id} />);
}
}
export default RenderFormFields;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment