Hi all I have following code: my code
I have following scenario. I am counting all my skill names char length and if that length is greater then 25 I am hiding all rest skills and showing in number how many skills is hided. That part is now working. But when I can't show my visible skills. Can you help me to resolve that problem and optimized my code if you think there is something wrong.
Thank you.
here my skills
const skills = [
{
id: 1,
name: "Html"
},
{
id: 2,
name: "css"
},
... and so on
];
my code part:
let lengthCount = 0;
let maxIndex = 0;
const skill = [];
const Skill = () => {
skills.map((item, index) => {
if (lengthCount <= 20) {
maxIndex = index;
skill.push(item.name); // I am adding items to my skill array
}
lengthCount = lengthCount + item.name.length;
});
// mapping items from skill array
let mySkills = skill.map((perSkill) => (
<span key={perSkill.id} className="element">
{perSkill.name}
</span>
));
return (
<div className="wrapper">
<div>{mySkills}</div>+{skills.length - maxIndex - 1}
</div>
);