Reputation: 11
i want get info firebase in expo, but i can't, I get this error
ERROR: child failed: path argument was an invalid path = "user/Carregando...". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"
i too tried using try and catch too, but it basically doesn't change anything, I don't know if the error is in the code or in the expo
ERROR WITH TRY/CATCH: error: SyntaxError: C:\Users\bellu\OneDrive\Desktop\Development\study\studydb\App.js: Unexpected token, expected "from" (10:0)
import { useEffect, useState } from 'react';
import {Text, View } from 'react-native';
import { db } from './src/database';
import { onValue, ref } from 'firebase/database';
export default function App() {
const [nome, setNome] = useState('Carregando...');
useEffect(() => {
function readData(){
const start = ref(db, 'user/' + nome);
onValue(start, (snapshot) => {
const data = snapshot.val();
setNome(data.nome)
})
}
try {
readData();
} catch (err) {
console.log(err)
}
}, [])
return (
<View style={{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}}>
<Text>{nome}</Text>
</View>
);
}
I tried get info in database, but what I try doesn't work
Upvotes: 1
Views: 48
Reputation: 598728
A path in the Firebase Realtime Database can not contain any .
characters, so the default value that you specify for nome
here is not valid:
const [nome, setNome] = useState('Carregando...');
Either specify the name of a user that actually exists, or use a different way to detect that the data is still loading, like:
const [nome, setNome] = useState();
...
<Text>{nome ? nome : 'Carregando...'}</Text>
Upvotes: 1