Skip to content
This repository has been archived by the owner on Aug 7, 2021. It is now read-only.

How to use React ScrollSpy with map function #209

Open
frietkip opened this issue Oct 20, 2020 · 0 comments
Open

How to use React ScrollSpy with map function #209

frietkip opened this issue Oct 20, 2020 · 0 comments

Comments

@frietkip
Copy link

frietkip commented Oct 20, 2020

Hey Makotot,

I really like your module! Well done :) I am running into an error when trying to use react-scrollspy in a map function. Below is an example of the code. I have a NavBar with all articles you can click on. But react scroll spy does not work.

NavBar generates the href=`/home#{$article.title} to link to the articles being generated by Articles

class Home extends Component {
render () {
const {articles} = this.props
return (

<div class='NavBar>
   {articles.map((items) => (
              <NavBar
                key={items.id}
                {...items}
              />
          ))}
</div>
<div class='Articles>
 {articles.map((items) => (
              <Articles
                key={items.id}
                {...items}
              />
          ))}
</div>
)
}
export default Home

NavBarArticles

class NavBar extends Component {
render () {
const {title} = this.props
return (
<Scrollspy
            items={title}
            currentClassName="is-active"
            componentTag="div"
>
<div id={id} class='navbar-item>
  <ul><a href={`/home#${title}}>{title}</a>
</div>
</Scrollspy>
)
}
export default Navbar
class Articles extends Component {
render () {
const {title} = this.props
return (
<div id={id} class='article-item>
  <ul><a href={`/home#${title}}>{title}</a>
</div>
)
}
export default Articles

Any suggestions on how to fix this?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant