I have an array of objects (here is only one but thats does not matter) in my JSON "dummy" back end. In each object I have a property "tags" which also contains simple array, let me show you an example
[
{
"title": "Get up and run",
"author": "Johnny",
"tags": ["react", "javascript"]
}
]
I tried to map an array which gave me a result: (see the code)
Article title: Get up and run
Writer: Johnny
Tags: reactjavascript
but i want to get result like that:
Article title: Get up and run
Writer: Johnny
Tags: react javascript (or "react, javascript" or "#react #javascript")
it seems I can't map "tag" array and main array of objects correctly same time. :( can u help me?
class Content extends Component {
state = {
posts: []
}
componentDidMount () {
axios.get("json-file.json")
.then(response => {
this.setState({posts: response.data.map(post => {
return post; /*here I get the whole data from dummy
backend */
})})
}
)
}
render () {
const post = this.state.posts.map(post => {
return <Post
title={post.title}
date={post.date}
author={post.author}
tags={post.tags.map(xTag => {
return xTag ;
})} /* I have other Component which correctly renders this...
no worries here */
/>
})
return (
<div>
{post}
</div>
)
}
}
I expect the better "map" of array I try to get result like this
Article title: Get up and run Writer: Johnny
Tags: react javascript (or "react, javascript" or "#react #javascript")
instead of
Tags: reactjavascript
or
Tags: ["react", "javascript"] (it was the worst version :)(its fixed ;) ) )
I want to map an array of objects and 'tags' array at same time and correctly,
How can I do that?