export const Articles = props => {
const [articles, setArticle] = React.useState(props.data || [])
React.useEffect(() => {
if (Array.isArray(articles) && articles.length < 1) {
setArticle([
{
title: 'how to map array in react',
content: `read this code!`,
},
])
}
}, [articles])
return (
<div>
{Array.isArray(articles) &&
articles.map((item, key) => (
<article key={key}>
<h2>{item.title}</h2>
<p>{item.content}</p>
</article>
))}
</div>
)
}