I'm trying to get data from a web page and print the contents to screen. Here is the code for HTTP get request:
https.get('https://jsonplaceholder.typicode.com/users', (resp) => {
let data = '';
// A chunk of data has been received.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
for (let i = 0; i < JSON.parse(data).length; i++)
cities += JSON.parse(data)[i].address.city + '\n';
console.log(cities);
});
At the code below i cannot print it to screen. I searched on Google but didn't come up with a solution.
let printing = "All users data:";
return <div className="App">
<header className="App-header">
<p>
{printing}
</p>
<p>
{cities}
</p>
</header>
</div>;
Here i can print the printing string but i can't print cities string.What is the reason for that? (Full code can be found at https://github.com/ezinal/reacttask/blob/master/src/App.js (39 lines))