Alex Yong
Alex Yong

Reputation: 7645

react function not render anything

I have problem rendering my ajax data in react.js. In my render function I have

{!isLoading &&
    this.renderList(items)
}

My renderList function as below

renderList(items) {
  ...    
  ...

  const renderLi = (statusObj) => {

    return ( <h1> something </h1> ) 

  }

  statusList.map(renderLi);
}

I suspect it's async problem, I console items in my renderList it did got the array of object through param passing, I'm lost.

Upvotes: 1

Views: 2082

Answers (1)

Shubham Khatri
Shubham Khatri

Reputation: 281656

The problem in your cod is that you are not returning anything from the renderList function and hence nothing gets rendered

Your return statement will be

{!isLoading &&
    this.renderList(items)
}

and your renderList function will be like

renderList(items) {
  ...    
  ...

  const renderLi = (statusObj) => {

    return ( <h1> something </h1> ) 

  }

  return (<div>{statusList.map(renderLi)}</div>);
}

Upvotes: 1

Related Questions