Skip to content

Instantly share code, notes, and snippets.

@abnersajr
Last active March 20, 2019 18:51
Show Gist options
  • Save abnersajr/c00962b777d5db64c1c9b50fd0b599b9 to your computer and use it in GitHub Desktop.
Save abnersajr/c00962b777d5db64c1c9b50fd0b599b9 to your computer and use it in GitHub Desktop.
Components
// Without Mapper
const UserName = ({name}) => (
<p>{name}</p>
)
const UserBio = ({firstName, lastName, birthDate}) => ( //...
<p>{firstName} {lastName} - {birthDate}</p>
)
// Mapper receives an object and return the formatted object
const userMapper = (data) => {
firstName: data.name,
lastName: data.lastName,
fullName: `${data.name} ${data.lastName}`
birth: data.birthDate,
};
// Provide api response to the mapper
const userData = mapper(apiResponse);
// You will the userMapper data in your components
const UserName = ({firstName}) => (
<p>{firstName}</p>
}
// <UserName {...userData} />
const UserBio = ({fullName, birth}) => (
<p>{fullName} - {birth}</p>
)
// <UserBio {...userData} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment