reactfire icon indicating copy to clipboard operation
reactfire copied to clipboard

Remove NO_ID_FIELD key from data hooks

Open jhuleatt opened this issue 4 years ago • 6 comments

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.

jhuleatt avatar Dec 02 '20 21:12 jhuleatt

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}".

SabrinaDanielle avatar Dec 13 '20 19:12 SabrinaDanielle

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;

SabrinaDanielle avatar Dec 13 '20 19:12 SabrinaDanielle

@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.

maxprilutskiy avatar Dec 30 '20 13:12 maxprilutskiy

@SabrinaDanielle it looks like the quickstart code is outdated, apologies for that. I filed #321 to fix the quickstart.

jhuleatt avatar Jan 06 '21 20:01 jhuleatt

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.

devth avatar Mar 08 '21 15:03 devth

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.

cd-a avatar Mar 21 '21 10:03 cd-a