How to use the react-firebase-hooks/firestore.useDocument function in react-firebase-hooks

To help you get started, we’ve selected a few react-firebase-hooks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github equithon / site-main / src / utils / siteAuth.js View on Github external
export const withCurUserInfo = Component => props => {
  const { state: { firebase } } = useContext(SiteContext);
  const { initialising, user } = useAuthState(firebase.auth);
  const { loading, value } = useDocument(
    firebase && firebase.firestore.doc(`users/${user && user.uid}`)
  );

  if(loading || initialising) return ;

  if(props.redirect) return Component;

  if(value === null || !value.exists) { // pass in current user's profile details
    return ;
  }

  try {
    const curUser = Object.assign({}, user, value.data());
    return 

  } catch(e) {
github bmcmahen / captioner / src / Editor.tsx View on Github external
export const Editor: React.FunctionComponent = ({
  match,
  history
}) => {
  const { id } = match && match.params;
  const [active, setActive] = React.useState(0);
  const [renderMain, setRenderMain] = React.useState(false);
  const [editNameMode, setEditNameMode] = React.useState(false);
  const theme = useTheme();

  // load the document containing meta about the project
  const { error, loading, value: meta } = useDocument(
    firebase
      .firestore()
      .collection("captions")
      .doc(id)
  );

  const [name, setName] = React.useState(meta ? meta.get("title") : "");

  const subcollection = firebase
    .firestore()
    .collection("captions")
    .doc(id)
    .collection("entries");

  // load the actual captions themselves
  const captions = useCollection(subcollection.orderBy("startTime"));
github equithon / site-main / src / app / views / rsvp / RsvpViewContainer.jsx View on Github external
const RsvpViewContainer = ({
  curUser,
  fetchRsvpFirestore,
  createRsvpFirestore,
  updateRsvpFirestore,
  submitRsvpFirestore
}) => {
  const { dispatch } = useContext(SiteContext);
  const { value } = useDocument(fetchRsvpFirestore());
  const [rsvpState, updateRsvpState] = useState("FETCHING");
  const [localRsvpInfo, updateLocalRsvpInfo] = useState({ submitted: false });
  const rsvpRef = useRef();
  rsvpRef.current = localRsvpInfo;

  const updateRsvpInfo = newRsvpInfo => {
    const newLocalRsvpInfo = {
      ...localRsvpInfo,
      ...newRsvpInfo
    };

    updateLocalRsvpInfo(newLocalRsvpInfo);
    if (!newLocalRsvpInfo.submitted)
      dispatch({
        type: "UPDATE_DASHBOARD_TOAST",
        data: { toastName: "rsvpModified" }
github equithon / site-main / src / app / views / application / ApplicationViewContainer.jsx View on Github external
const ApplicationViewContainer = ({
  curUser,
  fetchAppFirestore,
  createAppFirestore,
  updateAppFirestore,
  submitAppFirestore,
}) => {

  const { dispatch } = useContext(SiteContext);
  const { value } = useDocument(fetchAppFirestore());
  const [ appState, updateAppState ] = useState("FETCHING");
  const [ localAppInfo, updateLocalAppInfo ] = useState({ submitted: false });
  const appRef = useRef();
  appRef.current = localAppInfo;


  const updateAppInfo = newAppInfo => {
    const newLocalAppInfo = {
      ...localAppInfo,
      ...newAppInfo,
    };

    updateLocalAppInfo(newLocalAppInfo);
    if(!newLocalAppInfo.submitted) dispatch({ type: "UPDATE_DASHBOARD_TOAST", data: { toastName: "appModified" } });
  }
github bmcmahen / julienne / src / Recipe.tsx View on Github external
export const Recipe: React.FunctionComponent = ({ id }) => {
  const theme = useTheme();
  const user = useSession();
  const { value, loading, error } = useDocument(
    firebase
      .firestore()
      .collection("recipes")
      .doc(id)
  );

  if (loading) {
    return null;
  }

  if (!loading && !value.exists) {
    return null;
  }

  if (error) {
    return (

react-firebase-hooks

React Hooks for Firebase

Apache-2.0
Latest version published 2 years ago

Package Health Score

56 / 100
Full package analysis