2 ms·
Never used Google Ads, but you should be able to do something like var GoogleAd = React.createClass({ getInitialState: function() { return {
by spicyj 11y ago
Never used Google Ads, but you should be able to do something like
var GoogleAd = React.createClass({
getInitialState: function() {
return {
id: makeUniqueId()
};
},
render: function() {
// Since this is always the same, React won't try to change the contents
return <div id={this.state.id} />;
},
componentDidMount: function() {
googletag.defineSlot('/1234567/sports', [728, 90], this.state.id);
},
componentWillUnmount: function() {
// Clean up the slot and any other resources here
}
});
and then not worry about it.
- mbrock 11y agoIt would probably be good to supply a `key` property to the div to ensure that React never tries to reuse it (say, when changing from one GoogleAd to another).