Skip to content

Instantly share code, notes, and snippets.

@guillaumewuip
Created November 12, 2020 07:07
Show Gist options
  • Save guillaumewuip/24ea698d32e36a940973cb3930c134be to your computer and use it in GitHub Desktop.
Save guillaumewuip/24ea698d32e36a940973cb3930c134be to your computer and use it in GitHub Desktop.
State and Store in frontend codebase - State example - user API
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