realmの返り値を判定要素として使う場合の扱い方

読みだした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)と警告を受けます。

>株式会社シーポイントラボ

株式会社シーポイントラボ

TEL:053-543-9889
営業時間:9:00~18:00(月〜金)
住所:〒432-8003
   静岡県浜松市中央区和地山3-1-7
   浜松イノベーションキューブ 315
※ご来社の際はインターホンで「316」をお呼びください

CTR IMG