benwinding / react-admin-firebase

A firebase data provider for the react-admin framework
https://benwinding.github.io/react-admin-firebase/
MIT License
460 stars 178 forks source link

Write Sub Collection #220

Open anthony-dsf opened 2 years ago

anthony-dsf commented 2 years ago

Hello, we are using React-admin and Firestore throught React admin firestore, actually we are intenting to write a sub collection but we failed. below you'll find our code, anyone can help or explain how do this ? :

import { DeleteWithConfirmIconButton, EditableDatagrid, } from "@react-admin/ra-editable-datagrid"; import { Fragment } from "react"; import React, { useEffect, useState } from "react"; import firebase from "firebase/compat/app"; import { Create, CreateButton, List, SimpleForm, TextField, TextInput, ShowButton, EditButton, ReferenceManyField, ReferenceArrayInput, ChipField, SelectArrayInput, ReferenceInput, SelectInput, } from "react-admin"; import { db } from "./config"; import selectedIds from "./company"; import { collection, getDocs } from "firebase/firestore"; export const CreateGroupe = (props) => { const [users, setUsers] = useState([]); const messageRef = db .collection("company") .document("id") .collection("grou") .document("name_group"); useEffect(() => { const getUsers = async () => { const data = await getDocs(messageRef); setUsers(data.docs.map((doc) => ({ ...doc.data(), id: doc.id }))); }; getUsers(); }, []);

return (

{users.map((user) => { return (
{""}

Name: {user.name_group}

); })}

); }; export const GroupeList = (props) => { return ( <List {...props} hasCreate empty={false}>

</List>

); };

5hee75 commented 2 years ago

Please make an attempt to format your code in your summary - this is impossible to read.

myselfshravan commented 2 years ago

Even I am Trying to Read and Write the subcollection, Please Help me if there is a solution for that. photo_2022-07-24_10-28-20 photo_2022-07-24_10-28-09