Random Quote Machine - problem with Twitter button

Hey everyone!

I’ve almost finished my first front-end project: the random quote machine.

However, the only problem I have is that Twitter share quote isn’t updating when I click “New Tweet!”. I am guessing it’s because when the page loads for the first time, the twitter button takes the value of first quote, and doesn’t update itself when “New Tweet!” button is clicked.

But, that’s just my theory and I am not exactly sure how to get around it. So any help is much appreciated :).

Codepen link:
https://codepen.io/snjegurotska/pen/pmmJYz

Thanks,

MJ

hmmm … interesting problem, It is caused by your embedded script in the html file, the good news is that you don’t need it, just remove the script and all other refrences to it in your js file

 <a href={"https://twitter.com/intent/tweet?text=" + "\"" + this.state.quote + "\"" + " - " + this.state.author} target="_blank">Tweet</a>

the target="_blank" is needed to open the tweet in a new Tab as codepen will not allow you to reload in the same page.

The bad news is I’m not sure why the script is using the initial values only, not sure where you got it from but would have to look into it further.

1 Like

Hey, thanks for the quick feedback :slight_smile: !

I got the script from Twitter Developers Site, which I think is necessary to use the parameters.

Anyways, removing the script worked! Thanks!!

MJ