import React, { Component } from 'react';
import './App.css';
var convert = require('xml-js');
var xml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <todo>Work</todo>' +
'</note>';
class App extends Component {
constructor(props) {
super(props);
this.state = {
posts: []
}
}
componentDidMount() {
const result1 = convert.xml2json(xml, {compact: true, spaces: 4})
fetch(result1)
.then(response => response.json())
.then(json => this.setState({ posts: json }))
}
render() {
const { posts } = this.state;
return (
<div className="container">
{posts.map((post) => (
<div className="card">
{post.title}
<p className="text">{post.todo}</p>
</div>
))}
</div>
);
}
}
export default App;
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
is assigned a value but never used no-unused-vars