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

242
Vistas
Frontend (React) only solution for data structure and database

Problem Definition

I am having React App with small shop where all products are coming just from JSON file as external API since I am handling everything on fronten.

But I just got in one product that has limited amount -> I have only 20psc of that product and I am not sure how I can limit the users to purchasing more than I actually have.

Questions

  1. Is there a way (simplest possible) how I can limit amount of that product without using database or backend?
  2. Is there a way how I can actually show the users how much of that specific product is left? (imagine it as limited edition -> after every purchase number of product left will update live)

Is that somehow possible with still using just API or do I have to revert everything into DB (firebase for example)?

Any suggestions and example links I appriciate!

This is how I currently handle it with unlimited amount of products

// fetch data here

    const fetchData = () => {
            fetch('myAPIendpoint')
                .then((response) => response.json())
                .then((data) => {
                    setProducts(data);
                })
                .catch((error) => {
                    console.log(error);
                });
        };
        React.useEffect(() => {
            fetchData();
        }, []);

// adding product to cart

const onAdd = (product) => {
    const exist = cartItems.find((x) => x.id === product.id);
    if (exist) {
        setCartItems(
            cartItems.map((x) =>
                x.id === product.id ? { ...exist, qty: exist.qty + 1 } : x
            )
        );
    } else {
        setCartItems([...cartItems, { ...product, qty: 1 }]);
    }
};

// mapping items to show it in cart

 {cartItems.map((item) => (
.....
.....
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can just rewrite amount of product left dirrectly in your JSON file.

ex. Somebody buying some product -> request sent to your API -> you are reading the JSON file, looking for product by id(.find(product => producct.id === id)). Then you are checking quantity of product (do you have needed amount or not) if not, then returning some error, if yes, then you are doing rewrite of quantity property of the product inside file for current product and do other business logic.

Work with files depends on techonlogy/programmming language you use on back-end side. You can find it separately.

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