You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code works as expected in React Native but not in React:
consttasks=useQuery(Task);
Behavior:
When toggling or deleting a task, the tasks reference should be updated (it should be a new reference), but the reference does not get updated. Thus, the React component does not rerender.
The following code is a temporary solution users can implement as a workaround:
const[requeryFlag,setRequeryFlag]=useState(false);consttasks=useQuery(Task,(collection)=>collection,[requeryFlag]);useEffect(()=>{// The value doesn't matter, only that it is different from the initial value.setRequeryFlag(true);},[]);// <-- Only on mount is needed
Note that the useEffect() only needs to run on mount for useQuery() to correctly update.
The following code doesn't work in React: const task= useObject(Task, new BSON.ObjectId(user.id));
@elle-j FYI: I see the same issue on useObject() But if I place useObject() in the same hook together withuseQuery(), and use the workaround, it works as expected.
This is regarding React (not React Native) and our WASM build.
Dependencies Used
Problem
The following code works as expected in React Native but not in React:
Behavior:
tasks
reference should be updated (it should be a new reference), but the reference does not get updated. Thus, the React component does not rerender.realm-js/packages/realm-react/src/cachedCollection.ts
Lines 169 to 170 in 28a50dc
realm-js/packages/realm-react/src/useQuery.tsx
Lines 90 to 93 in 28a50dc
Workaround
The following code is a temporary solution users can implement as a workaround:
Note that the
useEffect()
only needs to run on mount foruseQuery()
to correctly update.Reproduce
Minimal local Realm app to reproduce the behavior: react-userquery-bug.zip
Notes
This issue does not seem to appear in React Native.
The text was updated successfully, but these errors were encountered: