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
interface CreateUserRequest { | |
username: string; | |
age: number; | |
email: string; | |
} | |
interface UpdateUserRequest { | |
username?: string; | |
age?: number; | |
email?: string; |
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
interface User { | |
username: string; | |
age: number; | |
email: string; | |
} | |
const createUser = (user: User) => { | |
//fetch request that requires all User properties | |
} |
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
interface User { | |
id: string; | |
updated_at: string; | |
username: string; | |
age: number; | |
email: string; | |
} |
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
type UserForm = Omit<User, 'id' | 'updated_at'>; |
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
let name = "Bob" | |
let age = 24 | |
name = age //hey you mutated the name variable! |
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
state = { | |
name: "Bob", | |
age: 24, | |
hobbies: ["swimming", "hiking"], | |
background: { | |
jobs: ["mechanic", "bank teller"], | |
}, | |
} |
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
state.hobbies.push("reading") |
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
const initialFormState = { | |
email: "", | |
password: "", | |
valid: false, | |
} | |
function Form() { | |
const [form, setForm] = useState(initialFormState) | |
//when updating the password field |
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
const [users, setUsers] = useState([ | |
{ id: 1, name: "Bob", age: 24, emailConfirmed: false }, | |
{ id: 2, name: "Sarah", age: 30, emailConfirmed: true }, | |
{ id: 3, name: "Kevin", age: 20, emailConfirmed: false }, | |
]) |
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
//confirmedUserId derived from email confirmation | |
setUsers(prevState => prevState.map(user => (user.id === confirmedUserId ? { ...user, emailConfirmed: true } : user))) |