I try to create simple app that generate random quote. I created a function that (i think) get a data i want from json file. But when i try to pass that function to my App function i get Error: Objects are not valid as a React child (found: [object Promise])
function Quote:
function Quote (data) {
var x = (Math.floor(Math.random() * (103 - 1) + 1) );
return fetch('https://gist.githubusercontent.com/camperbot/5a022b72e96c4c9585c32bf6a75f62d9/raw/e3c6895ce42069f0ee7e991229064f167fe8ccdc/quotes.json')
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson['quotes'][0]['author']);
return responseJson['quotes'][x]['author'];
})
.catch((error) => {
console.error(error);
});
}
App function:
function App() {
var text = '';
return (
<div id="quote-box">
<div id="author"><Quote /></div>
<button id="new-quote">New Quote</button>
<a href="twitter.com" id="tweet-quote">Tweet</a>
</div>
);
}
Quoteis not aReactcomponent. It's a function that returns a promise. I think you need to read the docs here to understand better how react components work.