Assign views randomly using an array - react native

Assign views randomly using an array - react native



I'm trying to come up with a way of randomly inserting views into a flexbox grid I've made in my app. The app looks like this



enter image description here



I have an array which will have a maximum of 6 elements, however these can change.
I want to insert these elements into the grid at random, however it's proving to be more difficult than I expected.



I grab the array asynchronously, so it needs to update on the fly.



Can anyone recommend any way of doing this? I'd post the code I've tried but it's pretty useless up to now.






You think your code is useless but maybe it is not, so just share it.

– devserkan
Sep 15 '18 at 20:38






You could randomly select an index of the array, populate the grid, and then pop that index from the array? Really need more info. Can you use a view more than once? What triggers the grid to get populated? I've used this function to randomly select from an array: const randomArrayIndex = (arr) => arr[Math.floor(Math.random() * arr.length)]; Not sure if this will point you in the right direction.

– Joe Fitzsimmons
Sep 15 '18 at 20:43





0



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)