Home > Back-end >  Can't find specific single user email query in Mongodb database?
Can't find specific single user email query in Mongodb database?

Time:05-07

API response show all user data in database to website UI

const [product, setProduct] = useState([]);
const [user] = useAuthState (auth)
useEffect(() => {
    const email = user.email;
    const url = `https://boiling-fjord-43680.herokuapp.com/productapi?email=${email}`;
    fetch(url)
        .then(res => res.json())
        .then(data => setProduct(data));
}, [user]);

CodePudding user response:

try to use params here , i have also faced the same problem and solved it in the following way:(note i have used id as identifier whereas u used email)

const { id } = useParams();

const [item, setItem] = useState({});

useEffect(() => { const url = https://floating-atoll-94813.herokuapp.com/item/${id}; fetch(url) .then((res) => res.json()) .then((data) => setItem(data)); }, []);

  • Related