Monday, June 30, 2025

How to Create Your First React App Step by Step (Beginner’s Guide)

 Are you new to React? Want to build your first React app but don’t know where to start?

Don’t worry! 😎 In this tutorial, I’ll show you step by step how to create your first React app using the popular tool Create React App.

By the end, you’ll have a running React project and understand the folder structure so you can start coding right away.

Step 1: Install Node.js

React uses Node.js and npm (Node Package Manager).
Download from 👉 https://nodejs.org/

After installing, check the versions:

bash

node -v npm -v


Step 2: Create the React App

Use npx (comes with npm) to quickly generate your project:

bash

npx create-react-app my-first-app

This creates a new folder called my-first-app with everything set up.

Step 3: Start the Development Server

Go to your project folder:

bash

cd my-first-app

Run:

bash

npm start

Your new React app will open automatically at:

arduino

http://localhost:3000

Step 4: Understand the Folder Structure

Here’s what’s inside:

bash

my-first-app/ ├── node_modules/ # dependencies ├── public/ # static files ├── src/ # your React code │ ├── App.js # main component │ └── index.js # entry point ├── package.json # project config

Step 5: Edit Your First Component

Open src/App.js and replace its content with:

jsx

function App() { return <h1>Hello React World!</h1>; } export default App;

Save the file – the browser will auto-refresh and show your message!


Step 6: Build for Production

When your app is ready to go live:

bash

npm run build

This creates an optimized build/ folder you can deploy to your server or services like  GitHub Pages.


What’s Next?

You can now:

Add new components
Use state and props
Connect APIs
Deploy online
React is fun and powerful – keep exploring! 🔥




Hope this guide helped you build your first React app easily!
👍 If you enjoyed this post, keep following the blog for more daily tips on JavaScript, React, and web development.

Thursday, January 11, 2018

How to force browser to update javascript files cache after deployment?

If you’re developing your project you might notice that in some browsers the changes you’ve made to your javascript files do not take effect immediately.

Sometimes it’s necessary to do a hard refresh[ctrl+f5] to see the updates take effect. But it’s unlikely that average web users know what a hard refresh is [because every one is not a developer :), nor can you expect them to keep refreshing the page until things straighten out even its not a good idea to ask user to refresh the page to see the current modification .. lol .

So how can you ensure that any updates you’ve made to your javascript will take place immediately for all users?

Here is the answer :)
I Created a javascript extension class, which has a static method and that method will embed a version to the end of the supplied javascript file.
public static class JavascriptExtension
{

   public static MvcHtmlString IncludeVersionInJs(this HtmlHelper helper, string filename)
   {
      string version = GetLastVersionNumber(helper, filename);
      return MvcHtmlString.Create("");
   }

  private static string GetLastVersionNumber(this HtmlHelper helper, string filename)
 {
   var context = helper.ViewContext.RequestContext.HttpContext;
   if (context.Cache[filename] == null)
   {
    var physicalPath = context.Server.MapPath(filename);
    var versionNo = $"?versionNo={new      System.IO.FileInfo(physicalPath).LastWriteTime.ToString("MMddHHmmss")}";

    context.Cache.Add(filename, versionNo, null,
    DateTime.Now.AddMinutes(5), TimeSpan.Zero,
    CacheItemPriority.Normal, null);
    return versionNo;
   }
   else
   {
      return context.Cache[filename] as string;
    }
  }
}

How to use this now? 

Use bellow code in your .cshtml pages
@Html.IncludeVersionInJs("/yourjavascriptfilename.js")

it will look like on the source as bellow

"type='text/javascript' src='/yourjavascriptfilename.js?versionNo=1218154859"
in the script tag

means when ever you changes on your javascript file and deploy to the server it will always compare with the versionNo from the cache and if found that related file has any changes then browser will download the latest one. So now you do not need to hard refresh the page and not to ask user to do the same.. :) 


Enjoy Coding :) and continue reading for next topic. 


Friday, September 8, 2017

Some basic command to run cordova app

Here are some basic commands use in cordova CLI


Build 
--->for android
cordova build android
cordova build android --release

--->for ios
cordova build ios
cordova build ios--release

Run
cordova run android   ---> for android
cordova run ios---> for ios

Get connected Devices list
adb devices

Get Platform List
cordova platform lst

Get Plugin list
cordova plugin lst

Add Platform
cordova platform add  

Add Plugin
cordova plugin add

Remove Platform
cordova platform remove  

Remove Plugin
cordova plugin remove








Friday, August 21, 2015

I will be back soon

Hi All,
     I will be back with some important post soon ...keep reading
Thanks

Monday, September 16, 2013

How to use SqlClient.SqlFunctions.DateDiff in LINQ?

Here i am showing how to use SqlClient.SqlFunctions.DateDiff in Entity Framework to delete some records which are older than 8 hours.
/// <summary>
        /// Function Name: DeleteAllOutDatedSession
        /// Bishnu Tewary
        /// 16-09-2013
        /// This function will delete all those records which are older than 8 hours
        /// </summary>
        /// <param name="objEntities">DEMOEntities needs to be submitted to enable SQL-Transactions including Rollbacks</param>
        /// <returns> Result Type</returns>
        public DB DeleteAllOutDatedSession(DEMOEntities objEntities)
        {
            Result = DB.Unknown;
            try
            {
                using (objEntities)
                {
                   (from p in objEntities.tblDEMO.Where(x => System.Data.Objects.SqlClient.SqlFunctions.DateDiff("hour", x.Timestamp, DateTime.Now) >= 8) select p).ToList().ForEach(objEntities.DeleteObject);
                    objEntities.SaveChanges();
                }
                Report(DB.OK);
            }
            catch (Exception ex)
            {
                this.Report(DB.Error, ex);
            }
            return Result;
        }

Friday, September 13, 2013

How to replace multiple characters from a string in C#

 static Dictionary<char, char> ToReplace = new Dictionary<char, char>() { { '*', ' ' }, { '%', ' ' } };

Here ToReplace dictionary contains all characters and its replacement as key value , here the char you want to replace is KEY and the KEY will be Replace with VALUE from the bellow function

 /// <summary>
        /// Funtion Name: ReplaceWildchars
        /// Bishnu Tewary
        /// 13-09-2013
        /// This function will replace wildchar from the string
        /// </summary>
        /// <param name="inputString">input string</param>
        /// <returns>retun string after replacing </returns>
        public string ReplaceWildchars(string inputString)
        {
            var tmpStr = inputString.Select(c =>
            {
                char r;
                if (ToReplace.TryGetValue(c, out r))
                    return r;
                return c;
            });
            return new string(tmpStr.ToArray()).Trim();
        }

Tuesday, September 10, 2013

Culture based jQuery datepicker in MVC4

Hi , I am going to show you today a very interesting thing :) which i implemented yesterday in my project, where requirement is to show datetime format of whole site to client's culture (means browser dependent culture,which we can have from the browser default language). I create a html helper class for this which took the   CurrentCulture from the Thread.CurrentThread and from there we can easily have the datetime format for our beautiful :) datepicker ok? from this "Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern" .

Now we have to call this html helper's methode which return dateformat for the datepicker like this.

Here one more thing i implemeted is to create a custom select button for the  datepicker,with this
.next(".ui-datepicker-trigger").addClass("Datepicker-Orange"); where "Datepicker-Orange" is the css class which replace the datepicker button style.

$(function () {
        $("#ReleaseDate").datepicker({
            showOn: "button",
            buttonImageOnly: false,
            buttonText: "select",
            changeMonth: true,
            changeYear: false,
            dateFormat: '@Html.ConvertDateFormat()',
            onSelect: function (dateText) {

            }
        }).next(".ui-datepicker-trigger").addClass("Datepicker-Orange");

        $(".ui-datepicker-trigger").mouseover(function () {
            $(this).css('cursor', 'pointer');
        });
    });


Here is the Helper class
using System;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq.Expressions;
using System.Threading;

namespace <Somenamespace>
{
    ///<summary>
    /// JQuery UI DatePicker helper.
    ///</summary>
    public static class JQueryUIDatePickerHelper
    {
        /// <summary>
        /// Function Name:ConvertDateFormat
        /// Bishnu Tewary
        /// 09-09-2013
        /// Converts the .net supported date format current culture
        /// format into JQuery Datepicker format.
        /// </summary>
        /// <param name="html">HtmlHelper object.</param>
        /// <returns>Format string that supported in JQuery Datepicker.</returns>
        public static string ConvertDateFormat(this HtmlHelper html)
        {
            return ConvertDateFormat(html,
        Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern);
        }

        /// <summary>
        /// Function Name:ConvertDateFormat
        /// Bishnu Tewary
        /// 09-09-2013
        /// Converts the .net supported date format current culture
        /// format into JQuery Datepicker format.
        /// </summary>
        /// <param name="html">HtmlHelper object.</param>
        /// <param name="format">Date format supported by .NET.</param>
        /// <returns>Format string that supported in JQuery Datepicker.</returns>
        public static string ConvertDateFormat(this HtmlHelper html, string format)
        {
            /*
             *  Date used in this comment : 9th - Sep - 2013 (Monday)
             *
             *  .NET    JQueryUI        Output      Comment
             *  --------------------------------------------------------------
             *  d       d               9           day of month(No leading zero)
             *  dd      dd              09          day of month(two digit)
             *  ddd     D               Mon         day short name
             *  dddd    DD              Monday    day long name
             *  M       m               9          month of year(No leading zero)
             *  MM      mm              09          month of year(two digit)
             *  MMM     M               Sep         month name short
             *  MMMM    MM              September    month name long.
             *  yy      y               13          Year(two digit)
             *  yyyy    yy              2013        Year(four digit)             *
             */

            string currentFormat = format;

            // Convert the date
            currentFormat = currentFormat.Replace("dddd", "DD");
            currentFormat = currentFormat.Replace("ddd", "D");

            // Convert month
            if (currentFormat.Contains("MMMM"))
            {
                currentFormat = currentFormat.Replace("MMMM", "MM");
            }
            else if (currentFormat.Contains("MMM"))
            {
                currentFormat = currentFormat.Replace("MMM", "M");
            }
            else if (currentFormat.Contains("MM"))
            {
                currentFormat = currentFormat.Replace("MM", "mm");
            }
            else
            {
                currentFormat = currentFormat.Replace("M", "m");
            }

            // Convert year
            currentFormat = currentFormat.Contains("yyyy") ?
        currentFormat.Replace("yyyy", "yy") : currentFormat.Replace("yy", "y");

            return currentFormat;
        }
    }
}

NOTE : you need to add
<globalization culture="auto" uiCulture="auto" /> in web.config
Cheers :)

How to convert a List to a comma separated string in C#

Here i am showing how to convert a List<int> to a comma separated string,
where
 malist is a list of PublisherID (int),
manList.Distinct() is distict list of PublisherID i.e removed all duplicate items from the malist and
objModel.TempCommaPublisher is s string 

Here is the sample code

List<int> manList = (from item in model.SearchList orderby item.PublisherID ascending select item.PublisherID).ToList();
           
            if (string.IsNullOrEmpty(objModel.TempCommaPublisher))
                objModel.TempCommaPublisher = string.Join<int>(",", manList.Distinct());


Here string.Join<int>(",", manList.Distinct()); join all int items from manList.Distinct() separated by a "," to a string .

How to get number of UPPER case letters in a string in C#?

 Here i am using LINQ to get number of uppercase letters within a string,this countUpperLetters method takes the string as parameter and returns number of uppercase letters on it.
    /// <summary>
        /// Function Name:countUpperLetters
        /// Bishnu Tewary
        /// 10-09-2013
        /// this countUpperLetters method takes the string as parameter
        /// and returns number of   uppercase   letters on it.
        /// </summary>
        /// <param name="strString">string parameter for which
        ///  uppercase letters will be counted
        /// </param>
        /// <returns>int , number of uppercase letteres</returns>
        public static int countUpperLetters(string strString)
        {
            return strString.Count(c => char.IsUpper(c));
        }

Monday, December 31, 2012

Happy New Year 2013

May The Every Moment Of Coming New Year Brings Happiness And Prosperity In Life, Enjoy The Every Moment Of Life. Happy New Year.

new year scraps
NextGenTech Software Solutions

Monday, September 3, 2012

How to Loading and Saving JSON data?

Here is a very good article for this
http://knockoutjs.com/documentation/json-data.html

Sunday, August 26, 2012

How to get Country list without using Database in C#?

 Do you know we can get Country List without using Database! Here i am showing how to get Country list by simply using the CultureInfo class .

This function ca be use for returning Country List by an region like here i used "de-DE" for Germany. for that you have to bake this function parametrized function by passing a string as regional code

/// Function Name: FillCountries
        /// Bishnu Tewary
        /// 01-02-2012
        /// <summary>
        /// This methode will set _countryList with country name in Germany
        /// </summary>
        private void FillCountries( )
        {
            this._countryList = new List<Country>();
            try
            {
                foreach (CultureInfo objCultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
                {
                    ////de-DE is for German and NativeName will return countryname in Germany
                    RegionInfo objRegionInfo = new RegionInfo("de-DE");
                    Country objCountry = new Country { CountryName = objRegionInfo.NativeName, CountryCode = objRegionInfo.TwoLetterISORegionName };
                    if (!this._countryList.Contains(objCountry))
                    {
                        this._countryList.Add(objCountry);
                    }
                }
            ////Sort this._countryList in ascending order
                this._countryList = (from c in this._countryList orderby c.CountryName ascending select c).ToList();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

Thursday, May 24, 2012

How to use gradient with background color?

 Here is how to use gradient with background color in css .
.HeaderWrapper {  
float:left; display:inline;
width:100%;
background:#5EB440 ;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#236F44', endColorstr='#5EB440'); /* for IE */
background: -webkit-gradient(linear, left top, left bottom, from(#236F44), to(#5EB440)); /* for webkit browsers */
background: -moz-linear-gradient(top,  #236F44,  #5EB440); /* for firefox 3.6+ */
}

How to make a rounded corner div?

Here is the style for making a rounded corner div

.round-corner-box {
margin:0px; padding:0px;
border:1px #5EB440 solid;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
-khtml-border-radius: 10px;
 border-radius: 10px;
}

But don't know this is not working in IE for me....
any suggestions! 

Tuesday, April 10, 2012

How to get the primarykey name of the table in EntityFramework C#?

 Here is how to get the primary key of an entitySetName
var primaryKeyName = objDb
   .MetadataWorkspace
   .GetEntityContainer(objDb.DefaultContainerName, System.Data.Metadata.Edm.DataSpace.CSpace)
   .BaseEntitySets
   .First(meta => meta.ElementType.Name == entitySetName)
   .ElementType
   .KeyMembers
   .Select(k => k.Name)
   .FirstOrDefault();

How to check the Key exists or not in EntityFramework C#?

This method will help to get the key exists or not from an entityset in EntityFramework
Here
TargetTable is the Enum where I have all the tables names
string keyValue is the value for which i am checking exists or not

 public bool CheckKey(TargetTable tableName, string keyValue, MyMotorEntities objDb)
{
bool isKeyAlreadyExists = false;
try
                            {
                                string entitySetName = Enum.GetName(typeof(TargetTable), tableName);
                                var primaryKeyName = objDb
   .MetadataWorkspace
   .GetEntityContainer(objDb.DefaultContainerName, System.Data.Metadata.Edm.DataSpace.CSpace)
   .BaseEntitySets
   .First(meta => meta.ElementType.Name == entitySetName)
   .ElementType
   .KeyMembers
   .Select(k => k.Name)
   .FirstOrDefault();
                                List<KeyValuePair<string, object>> lstEnum = new List<KeyValuePair<string, object>>();
                                lstEnum.Add(new KeyValuePair<string, object>(primaryKeyName, keyValue));
                                var lsttype = from t in lstEnum select t;
                                IEnumerable<KeyValuePair<string, object>> IeList = ((IEnumerable<KeyValuePair<string, object>>)lsttype).Select(x => x).AsQueryable();
                                System.Data.EntityKey key = new System.Data.EntityKey("MyMotorEntities." + entitySetName , IeList);
                                var tbl = objDb.GetObjectByKey(key);
if (tbl!=null)
                {
                    isKeyAlreadyExists = true;
                }
                            }
                            catch (Exception ex)
                            {

                            }
 return isKeyAlreadyExists;
}

Tuesday, March 20, 2012

How to get Value from an Enum Item in asp.net?

Here i am showing how to get value from an Enum Item

/// <summary>
        /// GetDescriptionFromEnumValue is returns the name or value for an Enum Item
        /// </summary>
        /// <param name="value">Enum Value</param>
        /// <returns>Description For Enum</returns>
        public static int GetValueFromEnum(Enum value)
        {
            FieldInfo fi = value.GetType().GetField(value.ToString());
            int val = (int)fi.GetValue(value);

            return val;
        }
Use this method
-----------------
 objtblLog.LogType = EnumUtility.GetValueFromEnum((Logtype)Session.ErrorLogtype);

Where Session.ErrorLogtype is an integer value

Thanks to my Project manager , who guide me lot to know these things and how to handle a project to get better performance ... "Thank you Sir"

How to get the Key from an Enum in asp.net?

This method will return the Key or Description from an Enum Item

 /// <summary>
        /// GetDescriptionFromEnumValue is returns the name  for an Enum Item
        /// </summary>
        /// <param name="value">Enum Value</param>
        /// <returns>Description For Enum</returns>
        public static string GetDescriptionFromEnumItem(Enum value)
        {
            DescriptionAttribute attribute = value.GetType()
                .GetField(value.ToString())
                .GetCustomAttributes(typeof(DescriptionAttribute), false)
                .SingleOrDefault() as DescriptionAttribute;
            return attribute == null ? value.ToString() : attribute.Description;
        }

Here how to use this function from other class
-----------------------------------------------
 /// Function Name: GetComTypes
        /// Bishnu Tewary
        /// 05-03-2012
        /// <summary>
        /// GetTitleNameByValue function return the Name of an enum item for its value
        /// </summary>
        /// <param name="value"> value of the enumitem</param>
        /// <returns>name of the value</returns>
        public string GetTitleNameByValue(int value)
        {
            TitleTypes enumItem = (TitleTypes)Enum.Parse(typeof(TitleTypes), Convert.ToString(value));
            return EnumUtility.GetDescriptionFromEnumItem(enumItem);
        }

How to use Description with an Enum Key in asp.net?

What happened if we have to bind a dropdownlist from Enum which holds Titles like Mr and Mrs but we have to show the textvaluefield like "Mr." and "Mrs."? Ok for this type of requirement we can use description attribute with the Key of a particular Enum, Here I am showing how to do that.

/// <summary>
        /// Enumeration TitleTypes use for getting the Titles
        /// Here I use DescriptionAttribute for holding the "Mr." Because "." is not supported in variable declaration
        /// </summary>
        public enum TitleTypes
        {
            /// <summary>
            /// Title As Mr and DescriptionAttribute set to Mr.
            /// </summary>
            [DescriptionAttribute("Mr.")]
            Mr = 1,

            /// <summary>
            /// Title As Mrs and DescriptionAttribute set to Mrs.
            /// </summary>
            [DescriptionAttribute("Mrs.")]
            Mrs = 2
        }

Cheers!