Basically I want show less description and when I press "Read More" I wanna show the full description
The code:
import { useState } from "react";
const JobsListing = ({ job }) => {
const [showFullDescription, setShowFullDescription] = useState(false);
let description = job.description;
if (!showFullDescription) {
description = description.setstring(0, 90) + "...";
}
return (
<div>
<div className="bg-white rounded-xl shadow-md relative">
<div className="p-4">
<div className="mb-6">
<div className="text-gray-600 my-2">{job.type}</div>
<h3 className="text-xl font-bold">{job.title}</h3>
</div>
<div className="mb-5">{description}</div>
<h3 className="text-indigo-500 mb-2">{job.salary}</h3>
<div className="border border-gray-100 mb-5"></div>
<div className="flex flex-col lg:flex-row justify-between mb-4">
<div className="text-orange-700 mb-3">
<i className="fa-solid fa-location-dot text-lg"></i>
{job.location}
</div>
<a
href={`/job/${job.id}`}
className="h-[36px] bg-indigo-500 hover:bg-indigo-600 text-white px-4 py-2 rounded-lg text-center text-sm"
>
Read More
</a>
</div>
</div>
</div>
</div>
);
};
export default JobsListing;
I expected to show the description from 0, 90 using setstring to show less description also when I click "Read More" I expect to show the full description
2
Answers
You’re not toggeling
showFullDescription
with the button, I’ve added anonClick()
Instead of the
if
at the beginning, use a ternary operator that will render the complete description, or usessubstring()
to only show the first 50 chars:Working example:
Try this.