Created
August 24, 2023 18:25
-
-
Save veektrie/22453d3ebb351489ed5004f64fc37dab to your computer and use it in GitHub Desktop.
my fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useState } from 'react'; | |
function Card({ title, text, target, linkTitle, href, rel, onClick }) { | |
return ( | |
<div className="card"> | |
<div className="card__title">{title}</div> | |
<div className="card__text">{text}</div> | |
<a className={`default-link card__link`} target={target} rel={rel} href={href} onClick={onClick}> | |
{linkTitle} | |
</a> | |
</div> | |
); | |
} | |
export default function Page () { | |
const [cards, setCards] = useState(); | |
useEffect(async () => { | |
var data = await fetch('https://my-json-server.typicode.com/savayer/demo/posts'); | |
let json = data.json(); | |
let newData; | |
json.forEach((item) => { | |
newData.id = item.id; | |
newData.title = item.title; | |
newData.link_title = item.link_title; | |
newData.link = item.link; | |
newData.text = item.body.en.substr(0, 50) + '...'; | |
}); | |
setCards(newData); | |
}); | |
function analyticsTrackClick(url) { | |
// sending clicked link url to analytics | |
console.log(url); | |
} | |
return ( | |
<div> | |
{cards.map(function (item) { | |
return ( | |
<Card title={item.title.en} linkTitle={item.link_title} href={item.link} text={item.text} onClick={analyticsTrackClick} /> | |
); | |
})} | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment