I'm using this component in my React Js web application: https://www.npmjs.com/package/react-faq-component.
const data = {
title: "FAQ (How it works)",
rows: [
{
title: "Lorem ipsum",
content: "Dolor sit amet",
},
],
};
I need to populate "rows:" with data retrieved by my API.
This is my code:
class Faqs extends Component {
constructor() {
super()
this.state = {
faqs: []
}
}
componentDidMount() {
let category = 'caategory1';
axios.get('https://myurl/api/faqs/'+category).then(response => {
this.setState({
faqs: response.data
})
})
}
render () {
const { faqs } = this.state;
const styles = {
titleTextColor: "black",
rowTitleColor: "black",
rowContentColor: 'grey',
}
const config = {
animate: true,
}
let data = {
title: 'FAQS (How it works)',
rows: [
// Here is where I'm trying to print the json data from the API
faqs.map(
(faq, index) => {
return (
`{title: ${faq.title}, content: ${faq.content}},`
)
}
)
]
}
}
I guess it's something about escaping but I'm a very beginner with React, so if anybody could help, I'd really appreciate it.
Thanks!