Hello All,
I have passed the Random Quote Project, but would really like to figure out why my tweet link gets the “Twitter.com is blocked - twitter.com refused to connect” error.
Code below:
const quoteBox =
"position-absolute top-50 start-50 translate-middle p-5 bg-white w-100 text-center shadow ";
const buttons = "position-absolute bottom-0 start-50 translate-middle-x p-5";
const buttonStyle = "btn btn-primary m-2";
const authorCenter = "text-center";
class Quote extends React.Component {
constructor(props) {
super(props);
this.state = {
data: [],
quote: "",
author: ""
};
this.random = this.random.bind(this);
this.handleClick = this.handleClick.bind(this);
}
componentDidMount() {
fetch(
"https://gist.githubusercontent.com/nasrulhazim/54b659e43b1035215cd0ba1d4577ee80/raw/e3c6895ce42069f0ee7e991229064f167fe8ccdc/quotes.json"
)
.then((response) => response.json())
.then((data) =>
this.setState({ data: data.quotes }, () => {
this.handleClick();
})
);
}
random() {
const randomIndex = Math.floor(Math.random() * this.state.data.length);
return this.state.data[randomIndex];
}
handleClick() {
const random = this.random();
this.setState({
quote: random.quote,
author: random.author
});
}
render() {
return (
<section>
<div id={"quote-box"}>
<div className={quoteBox}>
{" "}
{/*Container for quotes*/}
<div id={"text"}>
<h4>"{this.state.quote}"</h4>
</div>
<div id={"author"} className={authorCenter}>
<cite>- {this.state.author}</cite>
</div>
</div>
<div className={buttons}>
<button
id={"new-quote"}
onClick={this.handleClick}
className={buttonStyle}
>
New Quote
</button>
<a
className={buttonStyle}
id={"tweet-quote"}
href={`https://twitter.com/intent/tweet?text=${this.state.quote}`}
target={`_blank`}
>
<i className="fab fa-twitter"></i>
</a>
</div>
</div>
</section>
);
}
}
ReactDOM.render(<Quote />, document.getElementById("app"));