Hello,
I’m in the react course at the piece where we create a random percentage change of the price but I get a error:
" Type annotations can only be used in TypeScript files"
This is my code:
import React, { Component } from 'react'
import './Coin.css';
import PropTypes from "prop-types";
export default class Coin extends Component {
constructor(props){
super(props);
this.state = {
price: this.props.price
}
}
componentDidMount(){
const callback = () => {
// set the state to a new random value
const randomPercentage = 0.995 + Math.random() * 0.01;
// not allowed to change the value of the state
this.setState(function(oldState){
return(
price: oldState.price * randomPercentage
);
});
}
setInterval(callback, 1000)
}
render() {
return(
<tr className='coin-row'>
<td>{this.props.name}</td>
<td>{this.props.ticker}</td>
<td>${this.state.price}</td>
</tr>
);
}
}
Coin.propTypes ={
name: PropTypes.string.isRequired,
ticker: PropTypes.string.isRequired,
price: PropTypes.number.isRequired
}
Can you help me?
Thanks!