I am developing Currency Converter application using ReactJS. The program is about convert from one currency to another. The application has one form consist of a field with submit button. Moreover it also has initial currency 'USD 10' as a default.
When user type the an abbreviation of currency (e.g.: KRW) in the field and click the submit button. There will be a result below the form that shows the result of the conversion from USD to KRW. If the user want to add more currency, another selection currency will be shown below KRW conversion result.
When I am trying to make function to show the result when user submit the abbreviation of currency in the field.
This is the error:
Uncaught (in promise) TypeError: Cannot read property 'rates' of undefined
at Currency.render (App.js:402)
at finishClassComponent (react-dom.development.js:15319)
at updateClassComponent (react-dom.development.js:15274)
at beginWork (react-dom.development.js:16262)
at performUnitOfWork (react-dom.development.js:20279)
at workLoop (react-dom.development.js:20320)
at renderRoot (react-dom.development.js:20400)
at performWorkOnRoot (react-dom.development.js:21357)
at performWork (react-dom.development.js:21267)
at performSyncWork (react-dom.development.js:21241)
at requestWork (react-dom.development.js:21096)
at scheduleWork (react-dom.development.js:20909)
at Object.enqueueSetState (react-dom.development.js:11595)
at App.push../node_modules/react/cjs/react.development.js.Component.setState (react.development.js:336)
at Object.App.addCurrency [as onSubmit] (App.js:34)
at Form.handleSubmit (App.js:204)
And this is my code:
class Currency extends React.Component {
render() {
const p = this.props;
return (
<div className=currency>
{/*<span className=currencyText><Currency/></span>*/}
<div className=currencyInfo>
<div>{1 +p.base + = }</div>
<div>{p.data.rates}</div> {/*this is (App.js:402)*/}
</div>
</div>
);
}
}
Instead of that, If I code of Apps.js:402 like this:
<div>{p.data}</div>
and run the app, and check the console in chrome, the result for the line is empty.
The data that I mean is on the picture:
And this is the result of console prop p:
Any solution for this, so that I can retrieve the data rates from the currency?