I'm quite new to web development, I am wondering why when I call readContacts() in Contacts.js why the readContacts() function for ContactsContext.js does not output the return to my website? Thank you in advanced.
ContactsContext.js
import React, { useContext } from "react"
import { db } from "../firebase"
import { useAuth } from "./AuthContext"
const ContactsContext = React.createContext()
export function useContacts() {
return useContext(ContactsContext)
}
export function ContactsProvider({ children }) {
const { currentUser } = useAuth()
function createContact(email, firstName, lastName) {
db.ref("users/" + currentUser.uid + "/contacts/" + firstName + " " + lastName).set({
Email: email,
FirstName: firstName,
LastName: lastName
})
}
function readContacts() {
db.ref("users/" + currentUser.uid + "/contacts/").on("value", (snapshot) => {
return (snapshot.val())
})
}
const value = {
createContact,
readContacts
}
return (
<ContactsContext.Provider value={value}>
{children}
</ContactsContext.Provider>
)
}
Contacts.js
import React from "react"
import { ListGroup } from "react-bootstrap"
import { useContacts } from "../contexts/ContactsContext"
export default function Contacts() {
const { readContacts } = useContacts()
return (
<ListGroup variant="flush">
<ListGroup.Item>
{ readContacts() }
</ListGroup.Item>
</ListGroup>
)
}