Sorry for my bad English.. But I need help you guys! The problem is I wanna rerender when props change which is in EditField Components.
So I tried two ways,
first, I was trying to using useEffect parameter In UseEffect Hooks I tried useEffect(() => {},[facils]... like this way but when I tried this way, I got infinite rerender...
So I tried another ways, I passed GetDB function to EditField Components and when i edit my props data i tried call GetDBfunction.
But it didn't work what I expected...
could you give me any advices..?
const GetDB = () => {
const [facils, setFacils] = useState([]);
useEffect(() => {
firebase
.firestore()
.collection("facils")
.get()
.then((snapshot) => {
const newFacils = snapshot.docs.map((doc) => ({
id: doc.id,
...doc.data(),
}));
// prevent firebase quote exceed
console.log("!!!!FB warniing!!!!");
setFacils(newFacils);
});
}, []);
return facils;
};
const FacilityLists = () => {
const facils = GetDB();
const [id, setId] = useState([]);
const [name, setName] = useState([]);
const [showEdit, setShowEdit] = useState(false);
...
...
return (
<div>
<div style={{ display: "flex", justifyContent: "space-evenly" }}>
<div>Id</div>
<div>시설이름</div>
</div>
<div>
{facils.length > 0 ? (
facils.map((item) => (
<ul key={item.id} onClick={() => EditItem(item.id, item.name)}>
{item.id} - {item.name}
</ul>
))
) : (
<p>there is no data</p>
)}
</div>
<div>
{showEdit ? (
<EditField
id={id}
name={name}
showSave={() => setShowEdit(false)}
handleChange={handleChange}
refreshData={() => GetDB}
/>
) : (
<CreateField />
)}
</div>
</div>