Search code examples
javascriptserverclientcrudmern

Understanding on updating for CRUD application


Does anyone have a good explanation on how to make a client-side for a MERN-CRUD development? The problem I am having is with the updating part of CRUD. I can't seem to figure out how will it be possible to import data into the form so that it can be updated. Out of all the times, no data will pull up in the form once clicking on the edit form. Any information on how to understand this will be great. Thank You.


Solution

  • Lets say you have products in your database, you get those products with a query like SELECT * FROM products and you are iterating over them with .map()

    products.map((product) => {
              return (  
                <ProductComponent key={product.item_id} id={product.item_id} {...product}/>         
              );
            });
    

    also imagine that you have an update form in ProductComponent. You can access to the product's id in ProductComponent with props.id and can fill the form using props to access product's attributes (like price,name or etc) since we did {...product}. When you hit the update button, send the product id, form data and run the query