Home > Net >  Getting error while using state in class based component in react js
Getting error while using state in class based component in react js

Time:10-07

this is the code that i am writing.

It is the error that is showing.

Thank you for your help.

CodePudding user response:

The issue you are facing is that you are directly implementing the map function without enclosing it in any HTML tag.

For more reference: See this

Do it like this, your issue will be resolved

render() {
    return (
      <div>
        {this.state.articles.map((element) => {
          return <div>// Your further code here</div>;
        })}
      </div>
    );
  }

CodePudding user response:

You can directly return the map function without enclosing it in any HTML tag.

You just need to remove the curly braces.

  render() {
    return this.state.articles.map((element) => {
      return <div>{element}</div>;
    });
  }
  • Related