Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
Transfer active from NavLink
to Nav
(by the way, what will remain there after that? - yes, nothing but rendering a
, to which props are passed without changes; it turns out that this component is not really needed, it’s easier to create this one a
right away in Nav
), and store the index in it active element:
state = {
active: null,
...
}
setActive(active) {
this.setState({ active });
}
{this.state.items.map((n, i) => (
<li>
<NavLink
href="#"
className={this.state.active === i ? 'active' : ''}
onClick={() => this.setActive(i)}
>
{n}
</NavLink>
</li>
))}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question