I want to add the Twitter widget into React, but I don't know where to start or how to do it. I am very new to React JS.
Here is the HTML version of the code:
<div class="Twitter"> <a class="twitter-timeline" href="https://twitter.com/<%= @artist.twitter %>" data-widget-id="424584924285239296" data-screen-name='<%= @artist.twitter %>'>Tweets by @<%= @artist.twitter %></a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> </div>
And here is what I have so far:
React.DOM.div className: 'Twitter' children: [ React.DOM.a className: 'twitter-timeline' href: "https://twitter.com/" + artist.twitter 'data-widget-id': "424584924285239296" 'data-screen-name': artist.twitter children: 'Tweets by ' + artist.twitter React.DOM.script children: ... ]
I was planning to add the script where the dots (...) are, but that doesn't work. Thank you for your help.
Register the app via the Twitter Development Portal. https://developer.twitter.com and go to the Developer Portal. Go to a project (or create one if you don't have one yet). Go to + Add App > Create New App Instead. Name your app appropriately.
Twitter no longer allows this, you must use the twitter embed code generator on their publish.twitter.com site to select your widget embed code. Once on the site, you can select your customized desired widget based on the examples provided in the drop downs.
First load Widget JS in your index.html(before your React scripts). Then in your component, simply do the following. The widget JS will rescan the DOM.
componentDidMount: function() { twttr.widgets.load() }
See: https://dev.twitter.com/web/javascript/initialization
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With