Java script | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Java script

#Help_Post const App = () => { const getContacts = () => { getcontacts().then(contacts => { contacts.map((contact) => { console.log(contact.name); return( <div className = 'grow pa3 bg1 ma2 text-center br-pill shadow-3'> <p>{contact.name}</p> <p>{contact.email}</p> <p>{contact.phoneNumber}</p> </div> ); }); console.log(contacts); }) .catch(err => console.log(err)); } return ( <Base> {getContacts()} </Base> ); } in the above code when I map through the contacts in getContacts function, console.log(contact.name) provides the expected output but when I try to return JSX using the same, it returns nothing.

29th May 2020, 1:39 AM
ANKIT SRIVASTAVA
ANKIT SRIVASTAVA - avatar
2 Answers
+ 2
You are returning JSX from map method(is there a reason to do so?) but your getContacts function returns nothing. Declare an array at top of your getContacts function and push the contact objects(JSX) within map method. Then return the array from getContacts. [Edit some days later] I don't know if this is really what you need. I'm a beginner too.
29th May 2020, 2:38 AM
Kevin ★
+ 1
Try console.log(this.contact.name)
29th May 2020, 1:54 AM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar