Created
June 20, 2021 07:34
-
-
Save arifshariati/c607a2baf87976f8a2a2ce61c988db4f to your computer and use it in GitHub Desktop.
React Form Dynamic Rendering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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