Last active
March 20, 2019 18:51
-
-
Save abnersajr/c00962b777d5db64c1c9b50fd0b599b9 to your computer and use it in GitHub Desktop.
Components
This file contains hidden or 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
// 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