This post might seems similar to How do I get the proper text form from the firebase realtime database after querying via expo but it is not.
In this post, I would like to find out how do I randomize the shop names that I have retrieved from the database.
Currently the screen looks like this:
As you can see there is 2 different shop names appearing after a search from my database by the cuisine. But I would like the code to help me to pick which shop name to display, is it possible? And how would I implement in my code?
My current code for the above image is this:
import { StyleSheet, Text, View } from 'react-native'
import {db} from '../firebase'
import React, {useEffect, useState} from 'react'
import {ref, onValue} from 'firebase/database'
const SubScreen2 = ({route}) => {
const paramKey = route.params.paramKey
console.log(paramKey)
const [todoData, setToDoData] = useState([])
//const navigation = useNavigation()
console.log(paramKey)
useEffect (() => {
const starCountRef = ref(db, "food/" + paramKey);
onValue(starCountRef, (snapshot) =>{
const data = snapshot.val();
const newPosts = Object.keys(data).map(key =>({
id:key,
...data[key]
})
);
console.log(newPosts);
setToDoData(newPosts);
})
}, [])
return (
<View style = {styles.container}>
<Text style = {styles.header}></Text>
{
todoData.map((item,index) => {
return(
<View key ={index}>
<Text style = {styles.header}>{item.id}</Text>
</View>
)
})
}
</View>
)
}
export default SubScreen2