reactfire
reactfire copied to clipboard
Remove NO_ID_FIELD key from data hooks
Remove NO_ID_FIELD key from useFirestoreDocData,useFirestoreCollectionData, useDatabaseListData, useDatabaseObjectData.
This key is inserted when no idField option is passed to these functions. However, it ends up being pretty confusing. Instead, if idField is not provided, we can just omit the document id.
Hello, I think my issue may be slightly unrealtated; however, when following the example in the quickstart, instead of getting a boolean value I get "{NO_ID_FIELD: undefined}".
import React from "react";
import { useFirestoreDocData, useFirestore, SuspenseWithPerf } from "reactfire";
const Products = () => {
const burritoRef = useFirestore().collection("tryreactfire").doc("burrito");
// subscribe to a document for realtime updates. just one line!
const burrito = useFirestoreDocData(burritoRef);
if (burrito.status === "loading") {
return <p>Fetching burrito flavor...</p>;
}
return (
<SuspenseWithPerf
fallback={<p>"Loading store stuff..."</p>}
traceId={"Loading Store"}
>
<div>
Products
<p>
The burrito is
{burrito.yummy ? "good" : "bad"}!
</p>
</div>
</SuspenseWithPerf>
);
};
export default Products;
@jhuleatt Jeff, in that case, how do we get the id of a created document, when it's generated by Firebase?
I believe it makes sense to still have something like _uid attached to docs.
@SabrinaDanielle it looks like the quickstart code is outdated, apologies for that. I filed #321 to fix the quickstart.
Agree, why not default it to _id or something? Alternatively, let users set a global default so we don't have to keep passing { idField: "id" } on all useFirestoreCollectionData calls.
I agree with this. I'm even fine with keeping the current behaviour, as long as we have a way of omitting the id field completely.
We don't always need it. If I target a specific document only, I already know the Id, otherwise I can't target it. So having that field in there makes me have to filter it out every time i want to use the data.