I am trying to pass a property from one component down to another using Link from 'react-router-dom'.
The property I am trying to pass down is {this.props.postContent}
.
<Link to={
pathname: "/posts/" + this.props.postContent.id,
postContent={this.props.postContent}
}>
Read More...
</Link>
I first tried using only one curly brace in the Link to={
like how is shown in the correct answer of this SO post, however I get the error:
Parsing error: Unexpected token, expected "}"
I had a look in the documentation and can see that two sets of curly braces are used when adding a pathname, so I tried this instead:
<Link to={{
pathname: "/posts/" + this.props.postContent.id,
postContent={this.props.postContent}
}}>
Read More...
</Link>
But received the following error:
Parsing error: Unexpected keyword 'this'
Can somebody please give me additional advice on adding postContent
to a Link please?
** edit to show full component:
import React, { Component } from "react";
import { Link } from "react-router-dom";
import Post from "../components/post";
class PostSummary extends Component {
render() {
console.log("incoming", this.props.postContent.title);
return (
<div key={this.props.postContent.id}>
<h3 className="postTitle complements">
{this.props.postContent.title}
</h3>
<p className="postText">{this.props.postContent.text}</p>
<Link to={{
pathname: "/posts/" + this.props.postContent.id,
postContent={this.props.postContent}
}}>
Read More...
</Link>
<p className="postDate">
- Posted on {this.props.postContent.createdAt}
</p>
</div>
);
}
}
export default PostSummary;