Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Pure Component In React

import React from 'react';    
import PropTypes from 'prop-types';  
  
class Main extends React.Component {    
    constructor(props) {  
      super(props);          
      this.state = {  
         city: "Alwar",  
      }  
   } 
   
   componentDidMount(){
       setInterval(()=>{
           this.setState(()=>{
               return { city: "Alwar"}
           })
       },2000)
   }
   render() {  
       console.log('Main Component render');  
      return (  
          <div>    
         <h2>    
            {this.state.title}   
         </h2>    
         <p>User Name: {this.props.name}</p>  
         <p>User Age: {this.props.age}</p>  
         </div>  
      );    
   }  
     
}    
Main.propTypes ={  
       name:PropTypes.string.isRequired,  
       age:PropTypes.number.isRequired  
   }  
  
Main.defaultProps = {  
  name: 'Pankaj Kumar Choudhary',  
  age: 24  
};  
    
export default Main;
Comment

PREVIOUS NEXT
Code Example
Javascript :: router 
Javascript :: add event listeners 
Javascript :: useReducer Hooks 
Javascript :: js timer 
Javascript :: open source code 
Javascript :: convert number into string 
Javascript :: Material-ui Account Balance icon 
Javascript :: react datetime mannual editing 
Javascript :: node red push to array 
Javascript :: list of javascript cheat sheet 
Javascript :: redux if already exist item dont add to array 
Javascript :: javascript sort strings alphabetically 
Javascript :: Cannot GET /assets/vendor/swiper/swiper-bundle.min.js.map 
Javascript :: function find_max(nums) { 2 let max_num = Number.NEGATIVE_INFINITY; // smaller than all other numbers for (let num of nums) { if (num max_num) { // (Fill in the missing line here) } } return max_num; 
Javascript :: where to add const form = document.querySelector(".top-banner form"); form.addEventListener("submit", e = { e.preventDefault(); const inputVal = input.value; }); 
Javascript :: making all makers to show in react native map 
Javascript :: When an aqueous solution of AgNO3 is mixed with an aqueous solution of (NH4)2CrO4, a precipitation reaction occurs. For this reaction, a) Write the molecular equation. 
Javascript :: storybook absolute paths 
Javascript :: contries code react native 
Javascript :: kjkjl 
Javascript :: play store version of react native app 
Javascript :: generate tabuada java script 
Javascript :: select checkbox raitng in order javascript React 
Javascript :: How to use wildcard in Jason_VALUE 
Javascript :: find value number in enzym 
Javascript :: math.random and clone 
Javascript :: knockout framework 
Javascript :: pdf javascript search text 
Javascript :: backbone js event listener 
Javascript :: how to use ternary operatiion in sequelize join statement 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =