Created
August 4, 2021 03:40
-
-
Save jasonleehodges/4731410460d86990cad6c128b6859cf3 to your computer and use it in GitHub Desktop.
Composable User Form
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
import React, { FC } from 'react'; | |
export interface Contact { | |
name: string, | |
email: string, | |
phoneNumber: string, | |
referredBy?: string, | |
role?: string, | |
} | |
interface Props { | |
user: Contact; | |
setUser: (property: keyof Contact) => (e: React.ChangeEvent<HTMLInputElement>) => void; | |
className?: string; | |
} | |
export const UserForm: FC<Props> = ({ user, setUser, className, children }) => ( | |
<form className={className}> | |
<label>Name</label> | |
<input value={user.name} onChange={setUser('name')} /> | |
<label>Email</label> | |
<input value={user.email} onChange={setUser('email')} /> | |
<label>Phone Number</label> | |
<input value={user.phoneNumber} onChange={setUser('phoneNumber')} /> | |
{children} | |
</form> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment