class App extends React.Component {
constructor(props) {
super(props);
this.state = {
quote: “”,
author: “”,
backgroundColors: [ ]
}
}
componentDidMount() {
this.getQuotes();
}
getQuotes = async () => {
try {
const loadQuotes = await fetch(https://programming-quotesapi.vercel.app/api/random);
const data = await loadQuotes.json();
console.log(data);
const {author, quote} = data;
const newQuote = data.quote;
const newAuthor = data.author;
console.log(newQuote);
this.setState({
quote: newQuote,
author: newAuthor
})
} catch (err) {
console.log(err)
}
};
render() {
return (
{this.state.quote}
{this.state.author}
<a href={`https://twitter.com/intent/tweet?text=${encodeURIComponent(`“${this.state.quote}” — ${this.state.author}`)}`} target=“\_blank”>
New Quote
)
}
}
const rootElement = document.getElementById(‘quote-box’);
const root = ReactDOM.createRoot(rootElement);
root.render(
<React.StrictMode>
</React.StrictMode>
);