'Ad Manager in React

Hello I made an ad manager for a React project. It takes the dimensions of the spot it's given and chooses ads that will fit that spot.

My trouble is when the Ad Manager is included in a page, it rerenders with new ads on every state change.

How can I create this ad manager so it shows only one ad per page even when the component rerenders?

Code: https://pastebin.com/KjW0ikXs

  <div style={{ textAlign: 'center', margin: 'auto', display: 'table', cursor: 'pointer' }}>
    Ad
    <br />
    <Ad ad={ad} callback={callback} />
  </div>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source