Skip to content
Advertisement

Shuffling in react

I am fetching data from an api.Trying to make quiz application from the data of an API.I have selected random countries and their respective capitals and map them to my quiz application.I have achieved this already.Now i am trying to shuffle my answer options but not able to do that.anybody can please help? Here is my code

JavaScript

I have applied shuffle function but not sure whether its working or not

Advertisement

Answer

you can shuffle an array as so having a function in the component function body as below

JavaScript

and then in render you can invoke it as

JavaScript

added the relevant code only to keep it simple … hope it works and is the expected result

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement