2

Currently trying to learn react with firebase and keep getting some minor roadblocks.

As of now, I am trying to render the data from a selected item in a new page. The index page contains the following:

renderPosts(){
    return Object.keys(this.state.posts).map((post, index)=>(
        <div key={index} className="thumbnail">
        <h2>
          <Link to={`/view/posts/${post}`}>
            {this.state.posts[post].title}
          </Link>
        </h2>
        <p>{this.state.posts[post].body}</p>
        </div>
      ));
}

render() {
   return (
      <div>
        <div>
          {this.renderPosts()}
        </div>
        <View/>
      </div>
   )
}

As you can see it appends the ID of that post into the link so what I want to do now is to reach back into firebase and render the corresponding data of the item with that ID alone in a new page.

The ViewPost.js file as so:

constructor(props){
    super(props);
    this.state = {
      title: '',
      body: '',
    };
  }

  componentDidMount(){
    database.on('value', snapshot => {
      this.setState({
        post: snapshot.val()
      });
      this.props.match.params.postId;
    });
  }

  render() {
    return (
      <div >
       {this.state.props.title}
      </div>
    )
  }

Can you please show me what I’m doing wrong and how to do it?