ES6 array map doesn't return anything: ReactJS

后端 未结 2 640
慢半拍i
慢半拍i 2020-11-27 22:25

I have an array and i have a simple string value. I want to mapping my array because i\'m try to find my string value.

I have a code like this, but map function doe

2条回答
  •  臣服心动
    2020-11-27 23:17

    you should return the map function itself, and you can achieve it with es6 single line arrow functions too

    class Application extends React.Component {
      constructor(){
        super();
    
        this.state = {
          questionAnswer: 'is that possible',
          question: ['is', 'possible', 'that']
        }  
      }
    
      renderKeywords() {
        return this.state.question.map((item, i) =>{item}
       }); 
      }
    
      render() {
        return (
          
    blabla
    {this.renderKeywords()}
    ); } } React.render(, document.getElementById('app'));

提交回复
热议问题