Tuesday 5 March 2024

Refreshing Your UI Without Stopping or Removing the Container: A Guide to Docker and React

In today's fast-paced world, users expect web applications to be responsive and up-to-date. This means that your UI needs to be refreshed regularly to ensure a smooth user experience. However, stopping and removing containers can be time-consuming and may lead to downtime for your application. In this blog post, we'll discuss how to refresh your UI without stopping or removing the container using Docker and React.

Docker

Docker is a platform that allows you to build, ship, and run distributed applications. It provides a way to package your application and its dependencies into a container, which can then be run on any system that has Docker installed. This makes it easy to deploy your application to different environments, such as development, testing, and production.

React

React is a JavaScript library for building user interfaces. It allows you to create reusable components that can be easily integrated into your application. React is popular due to its simplicity, performance, and flexibility.

The Command

The command you provided is as follows:

docker run -p 5173:5173 -v "$(pwd):/app" -v /app/node_modules  react-docker-v1


Let's break down each element of the command:
  • docker run: This command starts a new container from an image.
  • -p 5173:5173: This flag maps port 5173 on the host to port 5173 in the container. This allows you to access the container's port from the outside world.
  • -v "$(pwd):/app": This flag mounts the current directory ($(pwd)) into the container at the path /app. This allows you to update your application's code without having to copy it into the container every time you make changes.
  • -v /app/node_modules: This flag mounts the node_modules directory from the container's working directory into the host's /app/node_modules directory. This ensures that your application's dependencies are always up-to-date.
  • react-docker-v1: This is the name of the Docker image you're using. It should be replaced with the name of the image you're using for your application.
How It Works

When you run this command, it starts a new container from the react-docker-v1 image. The container is mapped to port 5173 on the host, allowing you to access your application from the outside world. The current directory ($(pwd)) is mounted into the container at the path /app, allowing you to update your application's code without having to copy it into the container every time you make changes. The node_modules directory from the container's working directory is also mounted into the host's /app/node_modules directory, ensuring that your application's dependencies are always up-to-date.

Conclusion

By using Docker and React together, you can refresh your UI without stopping or removing the container. This allows you to keep your application running smoothly and ensures a great user experience. With the command provided, you can update your application's code and dependencies without having to stop or remove the container, making it easy to maintain and deploy your application.

Saturday 24 July 2021

Minimum Index Sum of Two Lists Algorithm Javascript

Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by unique strings.

You need to help them find out their common interest with the least list index sum. If there is a choice tie between answers, output all of them in alphabetical order. 

You could assume there always exists an answer.


Example 1:

Input: list1 = [Shogun, Tapioca Express, Burger King, KFC] , list2 = [Piatti, The Grill at Torrey Pines, Hungry Hunter Steakhouse, Shogun]

Output: [Shogun]

Explanation: The only restaurant they both like is "Shogun".

Thursday 10 June 2021

How to use componentWillUnmount with Functional Components in React

How to manage componentWillUnmount with useEffect

If you add a return function inside the useEffect function, it is triggered when a component unmounts from the DOM. This looks like:


import React, { useEffect } from 'react';

const ComponentExample => () => {

    useEffect(() => {

        return () => {

            // Anything in here is fired on component unmount.

        }

    }, [])

Thursday 20 May 2021

Angular 8 - Communicating Between Components with Observable & Subject

 

Observable.subscribe()

The observable subscribe method is used by angular components to subscribe to messages that are sent to an observable.

Subject.next()

The subject next method is used to send messages to an observable which are then sent to all angular components that are subscribers (a.k.a. observers) of that observable.


Sunday 16 May 2021

Render the view outside of view folder in ASP.NET mvc

 In normal case your project views(.cshtml) are in view folder of project but if you want to render the view from another folder with the same functionality of views. Then you have to just copy the web.config of views folder to your new folder and add the respective path like this.

View("~/Content/itemtemplate/Adtemplate.cshtml", model); 



Wednesday 12 May 2021

Details Summery Tag in HTML

 The <details> tag specifies additional details that the user can open and close on demand.

The <details> tag is often used to create an interactive widget that the user can open and close. By default, the widget is closed. When open, it expands, and displays the content within.

Tip: The <summary> tag is used in conjuction with <details> to specify a visible heading for the details.


Click Here for Example