Skip to content

Instantly share code, notes, and snippets.


Shyam Ghanshyam-K-Dobariya

View GitHub Profile
Ghanshyam-K-Dobariya /
Last active Aug 20, 2019
Value of this inside react component method

In a JavaScript method, the value of this has nothing to do with the class on which it was defined. Instead, it depends on the object that it was called upon.

import React from "react";
import ReactDOM from "react-dom";

class App extends React.Component {
  render() {
    var { handleClick } = this;
Ghanshyam-K-Dobariya / FormValidation.html
Created Aug 20, 2019
Basic form validation using vanila js
View FormValidation.html
<title>Parcel Sandbox</title>
<meta charset="UTF-8" />
function isValidEmailId(emailId) {
var exp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
return exp.test(emailId)

Ever wondered why setting array.length = 0 makes an array empty or array.length = 'some string' throws exception ? Code example.

screen shot 2018-09-14 at 10 16 50 

So now you have curiosity to know what happens in the background when command array.length = 0 takes place ?

Let's start this journey with below requirement.


Create a higher order function that accepts a react component. Do logs when life cycle methods (componentWillReceiveProps or render) are called


export function hocF (Component) {
  const cwp = Component.prototype.componentWillReceiveProps;
  Component.prototype.componentWillReceiveProps = function(...args) {
    console.log('in Component will receive props....'), ...args)
You can’t perform that action at this time.