Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!