'Rxdb myCollection.find().exec() returns null / previous document as response after myCollection.insert()

I am calling rxdbcollection.find() in a useEffect() hook after inserting a record into the rxdbCollection in the following way:

const [recordSaved,setRecordSaved]=useState<boolean>(false);
useEffect(()=>{
if(recordSaved && rxdbCollection){
const result = await rxdbCollection.find().exec();
}
},[recordSaved]);

onSaveButtonClicked = async()=>{
let doc = rxdbCollectionDocument = {id:'xyz',name:'Hello',description:'World'};
let result =  await rxdbCollection.insert(doc)
if(result === true){
setRecordSaved(true)
}
}

But I am getting null value always on the first save, only when i do another save, or another record save, then I am getting a record. When a new record is being inserted, i am able to get only the previous record added.

How can i get the current record as and when we are inserting into the rxdb.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source