Why am I getting Warning: Functions are not valid as a React child?

前端 未结 2 901
野的像风
野的像风 2021-01-18 04:20

When I try to call a method which returns the result of the map method, I get the following error Warning: Functions are not valid as a React child. This may happen if

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-18 04:49

    Warning: Functions are not valid as a React child. This may happen if you return a Component instead of from render

    Basically,React expecting the React Elements to render it.

    In current script,this.renderAlbums is a function reference which not returning any React Element.Function itself not react element.So,React unable to render the this.renderAlbums.

    
       { this.renderAlbums }
    
    

    correct way:

    
       { this.renderAlbums() } //it will return react element which can be rendered.
    
    

提交回复
热议问题