Skip to content

Instantly share code, notes, and snippets.

@treyhuffine
Last active March 3, 2020 10:54
Show Gist options
  • Save treyhuffine/ac0ea540a127abc41f9de78fca43caf8 to your computer and use it in GitHub Desktop.
Save treyhuffine/ac0ea540a127abc41f9de78fca43caf8 to your computer and use it in GitHub Desktop.
import * as React from 'react';
interface IUser {
username: string;
email: string;
password: string;
}
const ComplexState = ({ initialUserData }) => {
const [user, setUser] = React.useState<IUser | null>(initialUserData);
if (!user) {
// do something else when our user is null
}
return (
<form>
<input value={user.username} onChange={e => setUser({...user, username: e.target.value})} />
<input value={user.email} onChange={e => setUser({...user, email: e.target.value})} />
<input value={user.password} onChange={e => setUser({...user, password: e.target.value})} />
</form>
);
}
@muescha
Copy link

muescha commented Mar 6, 2019

Typo?
React.userState -> React.useState

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment