Created
November 12, 2020 07:07
-
-
Save guillaumewuip/24ea698d32e36a940973cb3930c134be to your computer and use it in GitHub Desktop.
State and Store in frontend codebase - State example - user API
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 DEFAULT_USER_PICTURE = "https://i.pravatar.cc/300"; | |
export const id = (user: User): string => user.id; | |
export const displayName = (user: User): string => | |
`${user.firstName} ${user.lastName}`; | |
export const pictureOrDefault = (user: User): string => | |
user.picture || DEFAULT_USER_PICTURE; | |
export const createNew = ({ | |
firstName, | |
lastName, | |
picture | |
}: { | |
firstName: string; | |
lastName: string; | |
picture?: string; | |
}): User => { | |
const id = `${Math.round(Math.random() * 1000000)}`; | |
return { | |
id, | |
firstName, | |
lastName, | |
picture | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment