Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-1685

useObject doesn't react to the object being inserted

      How frequently does the bug occur?

      All the time

      Description

      As a user, if I do the following const foo = useObject('foo', fooId) and foo is initially not in the database, I would expect the hook to re-render if the object with fooId is later inserted into realm. This is how most state libraries work in react. In practice, the way useObject works is that it will not re-render. The way to solve this is to do the following in the useObject hook:

      Try to get the object by primary key. If it exists setup a listener. Otherwise listen to its collection. In the collection listener callback, if the object has been inserted, setup the listener.

      Stacktrace & log output

      No response

      Can you reproduce the bug?

      Yes, always

      Reproduction Steps

      No response

      Version

      main

      What SDK flavour are you using?

      Local Database only

      Are you using encryption?

      No, not using encryption

      Platform OS and version(s)

      ios

      Build environment

      No response

      Cocoapods version

      No response

            Assignee:
            andrew.meyer@mongodb.com Andrew Meyer
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: