some null data gets included in my database when I store it on an array on my react native app even though it does not have any null entries on the firebase realtime database.
this is the firebase realtime database in my console.
This is my database get function:
const GetDatabaseData = () =>
{
if(DataRendered == false)
{
database()
.ref('Items/ItemInventory')
.on('value', Snapshot => {
var Data = []
Snapshot.forEach((child) => {
Data.push({
Item_code: child.child('Item_code').val(),
Item_name: child.child('Item_name').val(),
Item_qty: child.child('Item_qty').val()
})
})
console.log(Data)
//setItemData(Data)
})
}
else
{
console.log("Data Rendered")
}
}
it's my first time using firebase on react native so any help is appreciated.
This is the expected behavior. When Firebase sees a number of sequential, numerical keys it assumed that those are an array, and it fill missing indexes with null value.
To prevent this array coercion, use a short alphanumeric prefix on your keys, e.g. key1, key2, etc.
For more on this, see Best Practices: Arrays in Firebase.