2021年3月13日星期六

React passes prop in one situation but not another

I'm trying to pass the idea prop, which is an object, to IdeaBox, but it only works in one page and not the other. This code works:

render() {      return (        <div className="ideaFeed">          {this.state.ideasList.map(idea => (          <Link to={`/idea/${idea._id}`} key={idea._id}>            <IdeaBox idea={idea} />          </Link>        ))}        </div>      );    }  

But This code doesn't:

render() {      const idea = this.state.idea;      return (        <div>          <IdeaBox idea={idea} />        </div>      );    }  

Console.logging idea in both situations returns the same object. Why does it pass in the first situation but not the second?

https://stackoverflow.com/questions/66620988/react-passes-prop-in-one-situation-but-not-another March 14, 2021 at 12:05PM

没有评论:

发表评论