In my Story.js
component I am able to navigate to Comments.js
and pass in the storyID
in the url as shown below
export default function Story ({storyID}) {
const [story, setStory] = useState({});
useEffect(()=> {
getStoryTitle(storyID).then(data => data && data.url && setStory(data));
});
const kids = story.kids ? story.kids: [];
const author = story.by;
return (
<div className="story-wrapper">
<a className="a-tag" href={story.url}>
<p className="story-title">{story.title}</p>
</a>
<p className="story-author"><strong>By: {story.by}</strong> on {timeFormat(story.time)}</p>
<p className="story-comments"><Link to={`/comments/${storyID}`}>{kids.length}</Link> Comments</p>
{
My next step is just to be able to use that storyID
to display the comments in the Comments.js
component. But I am just a little tripped up on how exactly to pass in the storyID
. My Comments.js
code is set up like so
import React, {useState, useEffect} from 'react'
import {getStoryTitle} from '../API.js'
export default function Comments({storyID}) {
const [comment, setComment] = useState({});
const kids = comment.kids ? comment.kids: [];
useEffect(()=> {
getStoryTitle(storyID).then(data => && setComment(data))
}, [])
return (
<ul>
<li>{kids}</li>
</ul>
)
}