import React, { useState, useEffect } from "react";
Sunday, 20 February 2022
React - Multiple HTTP API call using Axios.all &&& Promise.all - fill in ag-grid-react
Wednesday, 16 February 2022
Convert Array of Object to array AND array to Array of Object - using map function in JS/TS
Convert JSON ARRAY to Array
=========================
var someJsonArray = [
{id:1, name: 'name1', property:'value1'},
{id:2, name: 'name2', property:'value2'},
id:3, name: 'name3', property:'value3},
];
using Arrow function:
-------------------------
var arrayData = someJsonArray.map( item => item.property )
/// output is ::: ['value1', value2','value3'];
///using without Arrow (=>) function
-----------------------------------------------
var arrayData someJsonArray.map( function(item) { return item.property; } );
Convert ARRAY to JSON Array
=========================
var arr = ['value1', value2','value3'];
let JsonArr = arr.map( val => { "key": val,"name": val, "value": val }
// this case all the key values same data [{key:1, name: 'name1', val:'value1'}, {}, {}]
without Arrow Function( => )
let JsonArr = arr.map( function(val)=> { return {"name": val, "value": val } });
Wednesday, 9 February 2022
How to deploy a React App to github Pages with github Actions:
How to deploy a React App to github Pages with github Actions:
===============================================================
create a repo in github.
Clone the peoject and then create react application
npx create-react-app react-github-pages-actions
npm install
npm i gh-pages --save-dev
add the package.json
{
"name": "react-github-pages-actions",
THEN "homepage": "https://[GITHUB_USERNAME}.github.io/react-github-pages-actions {project name}
...
...
}
,
"scripts": {
"predeploy": "npm run build",
"deploy" : "gh-pages -d build", // gh-pages is ceate a new branch to deploy from the branch merge the feature branch into main branch
// from main to gh-page will carete clone
"start": "react-script start",
....
....
...
}
Once the development is completed, run predeploy cmd
THEN run the deploymnet command
goto github -> settings -> pages -> you can see the url is deploy in github pages.
We can change the branch name and post the root/ docs save
Addding Github actions to react project:
---------------------------------------
create .github folder in the project root directory inside create another directory -> workflow (folder ) -> then create file workflow.yml
Monday, 31 January 2022
How to check data type or validate data in React js
there are two data types in Javascript
primitive
String,
Number,
Boolean,
Undefined,
and NULL
non-primitive types:
Object,
Array,
and RegExp
To check the data belongs to which data type there is an inbuilt javascript method called typeof. typeof can be used for validating the data type but there is one weird behavior of typeof Array that it gives us object as output.
console.log(typeof(new Date())) // object
console.log(typeof(['Manish', 'Manntrix', "Medium"])) // object
console.log(typeof({ name: 'Manish', age: 26 })) // object
console.log(typeof(/ab+c/i)) // object
console.log(typeof(new Error('Error'))) // object
To solve the issue
- Open your project directory and install xtypejs.
npm install xtypejs --save2. Now import xtype from xtypejs library.
import xtype from 'xtypejs'| console.log(xtype(new Date())) // date console.log(xtype({})) // empty_object | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(xtype({name: "manish"})) // single_prop_object | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(xtype({name: "manish", age: 26})) // multi_prop_object | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(xtype([])) // empty_array | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(xtype([1])) // single_elem_array | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(xtype([1, 2])) // multi_elem_array | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(xtype(undefined)) //undefined | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(xtype(1)) //positive_integer | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(xtype(1.1)) //positive_float | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(xtype(-1.1)) //negative_float | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(xtype(-1)) //negative_integer | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(xtype('Hello')) //multi_char_string | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(xtype(' ')) //whitespace | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(xtype('')) //empty_string | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(xtype(NaN)) //nan | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(xtype(new Error())) //error | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(xtype(/ab+c/i)) //regexp | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(xtype(true)) //true | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
console.log(xtype(false)) //false
|
KISS, DRY, SOLID, YAGNI — A Simple Guide to Some Principles of Software Engineering and Clean Code
1 — KISS (Keep It Simple, Stupid) Simplicity triumphs over complexity. Direct and clear codes are better for developing, maintaining, and s...
-
Cross browser testing - automation framework-cypress,playwrite; CloudBorwser -saucelabs browserstackEvaluating cross-browser testing for a React application involves assessing both functional consistency (JavaScript/API behavior) and v...
-
Top 10 Web Application Security Risks There are three new categories, four categories with naming and scoping changes, and some consolidat...