S
S
SerjAndreev2019-08-11 17:39:59
JavaScript
SerjAndreev, 2019-08-11 17:39:59

Dynamic tag and key?

There are a number of tags that are stored in the store, I display them in the component, it requires a key, please tell me how to add ?, and how to add a class to these items?

class Main extends Component {
  render() {

    return (
      <article className="main">
        <div className="main-root">
        	{ this.props.counter.map((item) => React.createElement(`${item.tag}`))}
        </div>
        <Edit/>
      </article>
    );
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-08-11
@SerjAndreev

Option using JSX:

class Main extends Component {
  render() {

    return (
      <article className="main">
        <div className="main-root">
          {this.props.counter.map(({ tag: Tag }, i) => <Tag key={i} />)}
        </div>
        <Edit/>
      </article>
    );
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question