I
I
ironmansl2019-11-25 15:07:42
JavaScript
ironmansl, 2019-11-25 15:07:42

How to fix error after removing return?

There is this code:

{this.props.items.map((n, i) => {
          return (
            <button
              data-index={i}
              onClick={e => this.props.changeTab(+e.target.dataset.index)}>
              {n.content}
            </button>
          );
        })}

I wanted to try to write this code without return, writing instead: ( ). Like this:
{this.props.items.map((n, i) => ({
            <button
              data-index={i}
              onClick={e => this.props.changeTab(+e.target.dataset.index)}>
              {n.content}
            </button>
        });)}

But I have an error:
5ddbc320d524c437169645.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dev null, 2019-11-25
@ironmansl

{this.props.items.map((n, i) => (
            <button
              data-index={i}
              onClick={e => this.props.changeTab(+e.target.dataset.index)}>
              {n.content}
            </button>
        );)}

P
Petr Muhurov, 2019-11-25
@pterodaktil

{this.props.items.map((n, i) => (
            <button
              data-index={i}
              onClick={e => this.props.changeTab(+e.target.dataset.index)}>
              {n.content}
            </button>
        )}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question