Hello There,
I did not write React for more than a year and i may have forgotten a lot (if not everything )
I have a quick test for a job interview but i am stuck with the render of the following code,
can you please help?
import React, { Component } from 'react'
// import Data from '../d ata/rates.json'
import io from 'socket.io-client/dist/socket.io';
import SimpleDateTime from 'react-simple-timestamp-to-date';
class RatesList extends Component {
constructor() {
super();
this.state = {
ratesList: []
}
}
getDataList() {
const io = require('socket.io-client');
const socket = io('https://wss.live-rates.com/')
var key = 'trial ' //YOUR LIVE-RATES SUBSCRIPTION KEY
socket.on('connect', function () {
socket.emit('key', key);
});
socket.on('rates', function (msg) {
try {
let obj = JSON.parse(msg);
console.log(obj);
this.setState({
ratesList: obj
})
} catch (e) {
console.log(msg);
}
});
}
componentDidMount() {
this.getDataList();
}
renderData() {
this.state.ratesList.map((rates) => {
return <div>
<h1>Currency {rates.currency}</h1>
<p> rate {rates.rate}</p>
<p> bid {rates.bid}</p>
<p> ask {rates.ask}</p>
<p> high {rates.high}</p>
<p> low {rates.low}</p>
<p> open {rates.open}</p>
<p> close {rates.close}</p>s
<SimpleDateTime> date={rates.timestamp} </SimpleDateTime>
</div>
})
}
render() {
return (
<div>
<h1>Hello There</h1>
{this.renderData()}
</div>
)
}
}
export default RatesList```
I see the connection running in the console but nothing in the html.
Do you know what i did do wrong ?
Thanks