Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
How to get data from server to client side based on same kind of value in react?

I am trying to get data from server to my client side based on a value.Those datas email address matched I only want those to get. But I can not get the data and in the server side the email value is showing undefined. My client side code is given below where I am trying to get data and send email to the server side.

This is my client side code:

const Myproducts = () => {
const [user] = useAuthState(auth);
const [myproducts, setMyproducts] = useState([]);
    useEffect(() => {
        const email = user?.email;
        fetch(`http://localhost:5000/useritems?email=${email}`)
            .then(res => res.json())
            .then(data => setMyproducts(data))
    }, []);
}

And my server side code is given below where I am trying to get data from mongodb and console.log(email). But the email is showing undefined.

This is my server side code:

app.get('/useritems', async (req, res) => {
    const email = req.query.email;
    console.log(email);
    const query = { email: email };
    const cursor = productCollection.find(query);
    const products = await cursor.toArray();
    res.send(products);
});

What's wrong with my code. How can I solve this problem? Any tips to solve this problem?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

According to this answer https://stackoverflow.com/a/6912872/15892381 you can access the req.query in express base apps in Node.Js you can just use url parser from url module and read the query from that:

const url = require('url');
const url_parts = url.parse(request.url, true);
const query = url_parts.query;
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda