Last active
November 30, 2020 09:08
-
-
Save createdbymahmood/e0911ef620c45d0a46e2966b5241a948 to your computer and use it in GitHub Desktop.
How to render input/textarea based on some conditions
This file contains hidden or 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
function isPropsForTextareaElement( | |
props: InputProps | TextareaProps | |
): props is TextareaProps { | |
return "rows" in props; | |
} | |
export const TextareaInputGeneralComponent = ( | |
props: InputProps | TextareaProps | |
) => { | |
if (isPropsForTextareaElement(props)) { | |
return <textarea {...props} />; | |
} else { | |
return <input {...props} />; | |
} | |
}; // optionally use a custom type guard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment