2023-09-27
読みだしたrealmデータの有無を確認するには、データの長さ、つまりlengthを測ってそのデータが
あるかどうかをコンソールで見ます。
データ自身はオブジェクトで返ってくるので、そのデータが何もなければ偽を、一つでも
データが入っていれば真の結果が返ってきます。
const Schema = {
name: "Cource",
properties: {
name: "string",
data: "int?",
},
try{
const realm = await Realm.open({
path: "myCource",
schema: [Schema],
});
task = realm.objects("Cource");
if(task.length > 0){
navigation.reset({
index: 0,
routes: [{ name: 'main' }],
});
}
}catch(error){
console.log('エラー' + error.message);
}
task.lengthでなく「task」のまま判定対象にした場合は
Possible Unhandled Promise Rejection (id: 0)と警告を受けます。