-
Notifications
You must be signed in to change notification settings - Fork 575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useObject doesn't react to the object being inserted #4514
Comments
@mfbx9da4 Yes, this is indeed a problem. We will look into it and get back to you when we have a fix. |
@takameyer EDIT: So this is my workaround which does follow new inserts: // replace this
const cat = useObject('Cat', 12)
// with
const cat = useQuery('Cat').filtered('id == 12')[0] |
@mordechaim That is similar to the workaround I would've suggested. Thanks for sharing! The solution to this problem will be something similar. We will have to register a listener on the filtered parent collection and update the state when the object appears. |
Argh, just ran into this issue :( |
* Prime any list properties with an cachedCollection so that updates fire correctly (Fixes #5185) * Primary Keys as non-primative values would reset the cached objects, since their reference always changes * Create a listener on the collection if the object doesn't exist, and rerender when it is created (Fixes #4514)
* Prime any list properties with an cachedCollection so that updates fire correctly (Fixes #5185) * Primary Keys as non-primative values would reset the cached objects, since their reference always changes * Create a listener on the collection if the object doesn't exist, and rerender when it is created (Fixes #4514)
The PR #5208 will fix this issue. Now, when the object does not exist, there will be a listener established on the collection that will re-render when an object with the given primary key comes into existence. |
@takameyer I still have this issue! |
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 withfooId
is later inserted into realm. This is how most state libraries work in react. In practice, the wayuseObject
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
The text was updated successfully, but these errors were encountered: