Im new in React js and I want to add Read More Functionality in React Js. im fetching title and its body on two pages i.e titles on 1 page and its body description in another page/route etc . But I want whenever i click on title its whole description along with title open in another page.and Im using DummyJsonAPi.
->https://dummyjson.com/docs/posts
Here is my code where im fetching all the titles from dummyapi
import React, { useEffect, useState } from "react";
import { v4 as uuidv4 } from "uuid";
import { Link } from "react-router-dom";
const HomeMainContent = () => {
const [data, setData] = useState(null);
useEffect(() => {
fetch("https://dummyjson.com/posts")
.then((response) => response.json())
.then((data) => {
const postText = data.posts.map((postData) => {
return { title: postData.title };
});
setData(postText);
});
}, []);
return (
<React.Fragment>
<div className="container px-4 px-lg-5">
<div className="row gx-4 gx-lg-5 justify-content-center">
<div className="col-md-10 col-lg-8 col-xl-7">
<div className="post-preview">
{data
? data.map((meaning) => {
return <h2 className="post-title" key={uuidv4()} ><Link to="/post">{meaning.title}</Link> <hr/> </h2>;
})
: null}
</div>
<div className="d-flex justify-content-end mb-4">
<a className="btn btn-primary text-uppercase" href="#!">
More Posts →
</a>
</div>
</div>
</div>
</div>
</React.Fragment>
);
};
export default HomeMainContent;
And here is my code where im fetching all the body text from an dummy api
import React, { useEffect, useState } from "react";
import { v4 as uuidv4 } from "uuid";
const PostMainContent = () => {
const [data, setData] = useState(null);
useEffect(() => {
fetch("https://dummyjson.com/posts")
.then((response) => response.json())
.then((data) => {
const postText = data.posts.map((postData) => {
return { body: postData.body };
});
setData(postText);
});
}, []);
return (
<React.Fragment>
<article className="mb-4">
<div className="container px-4 px-lg-5">
<div className="row gx-4 gx-lg-5 justify-content-center">
<div className="col-md-10 col-lg-8 col-xl-7">
{data
? data.map((meaning) => {
return <p key={uuidv4()}>{meaning.body} </p>;
})
: null}
</div>
</div>
</div>
</article>
</React.Fragment>
);
};
export default PostMainContent;
Now i want to click any title and open its body description in another page . How can i achieve this . POV: i dont know REDUX . Thanks in advance