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
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 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
You think your code is useless but maybe it is not, so just share it.
– devserkan
Sep 15 '18 at 20:38