Shuffle Array click handler event help React


So I have the following code that shuffles an array and returns a pair of words

const words = 
  [ 'monitor', 'program', 'application', 'keyboard'
  , 'javascript', 'gaming', 'network'
  ]
for (let i = words.length; --i;)  // shuffle Array
  {
  let j = Math.floor(Math.random() * (i + 1));
  [words[i], words[j]] = [words[j], words[i]]
  }

// get 2 random words
console.log( words[0], words[1] )

I want to return each word in its own button like the following picture:
Each time a button is selected with an onClick I want the page to rerender with a new set of questions. How can I do this in React?
enter image description here

Source: JavaSript – Stack Overflow

November 5, 2021
Category : News
Tags: javascript | onclick | reactjs

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.