Posts

Showing posts from May, 2022

nodecors

 https://stackoverflow.com/questions/57009371/access-to-xmlhttprequest-at-from-origin-localhost3000-has-been-blocked if you are building your rest api in nodejs. Follow the folowing simple steps Stop the Node.js server. npm install cors --save Add following lines to your server.js or index.js var cors = require ( 'cors' ) app. use ( cors ()) // Use this after the variable declaration Now try to make your api call on the client side and it should work related to package.json error: Cannot find schema for package.json · Issue #138459 · microsoft/vscode · GitHub "scripts" : {      "start" : "nodemon app.js" ,        },

react js form with post api

import   axios   from   'axios' ; import   React ,{ useEffect ,  useState }  from   'react' function   Form () {      const   initialvalue ={ username : '' , userpwd : '' };      const  [ state , setState ]= useState ( initialvalue )      const   username = state . username ;      const   userpwd = state . userpwd ; const  [ formerror , setFormerror ]= useState ({});    const  [ submit , isSubmit ]= useState ( false ); const   handlechange =( e ) => { //console.log(e.target.name); const  { name , value }= e . target ;    setState ({... state , [ name ]: value }) } const   Validate =( state ) => {      const   error ={}      const   regexpusername = / ^ [ a-zA-Z ] + $ / ;      const   regexpassword = / ^ [ a-zA-Z0-9 ] \w ...

reactfetchingdata

  1:--using fetch import   React ,{ useState , useEffect }  from   'react' export   default   function   Fetch () {    const  [ post , setPost ]= useState ([]);    useEffect (() => {      fetch ( `https://jsonplaceholder.typicode.com/posts` )     . then (( response )  =>  {            response . json (). then ( data => {            console . log ( data );            setPost ( data );       }                  )     })     . catch (( error )  =>  {     console . log ( error );        // Code for handling...

menu_css

<! DOCTYPE   html > < html   lang = "en" > < head >      < meta   charset = "UTF-8" >      < meta   http-equiv = "X-UA-Compatible"   content = "IE=edge" >      < meta   name = "viewport"   content = "width=device-width, initial-scale=1.0" >      < title > Document </ title > < link   rel = "stylesheet"   href = "style/menurev.css" > </ head > < body >      < div >      < ul >          < li >< a   href = "#" > Home </ a ></ li >          < li >              < a   href = "#" > Aboutus </ a >            ...

REACT_USEFFECTFORM

  import   React  ,{ useState , useEffect }  from   'react' import   axios   from    'axios' export   default   function   FormApi () {      const [ post , setPost ]= useState ({});      const  [ id , setid ]= useState ( 1 ); const  [ idbuttonclick , setidbuttonclick ]= useState ( 1 );      const   handleclick =() => { //alert(id); setidbuttonclick ( id );     }      useEffect (         () => {          axios . get ( `https://jsonplaceholder.typicode.com /posts/ ${ idbuttonclick } ` ). then ( res => {              console . log ( res )              setPost ( res . data );      ...

Form_reactjs

  import   React ,{ useState }  from   'react' ; export   default   function   Form () {      const   initalvalues ={ username : '' , userpass : '' }      const  [ state ,  setState ] =   useState ( initalvalues ); const  [ formError , setFormErrors ]= useState ({})      const   username = state . username ; const   userpass = state . userpass ; const   handlechange =( e ) => { console . log ( e . target ); const  { name , value }= e . target ; setState ({... state , [ name ]: value }) } const   handlesubmit =( e ) => {      e . preventDefault ();      Validate ( state ); } const   Validate =( state ) => { //console.log("username"+state.username); //console.log("password"+state.userpass); const   errors ={}; const   regexusername = / ^ [ A-Z a-z \\ s ] + $ / ; const ...

angular routing dynamic

  < p > nav1 works! </ p > < nav >      < ul >        < li >< a   routerLink = "/Home"   routerLinkActive = "active" > Home </ a ></ li >        < li >< a   routerLink = "/Aboutus"   routerLinkActive = "active" > AboutUs </ a ></ li >        < li >< a   routerLink = "/Profile"   routerLinkActive = "active" > Profile </ a ></ li >        < li >< a   routerLink = "/User/1"   routerLinkActive = "active" > User </ a ></ li >        < li >< a   routerLink = "/User/2"   routerLinkActive = "active" > User2 </ a ></ li >      </ ul >    </ nav >    <!-- The routed...

react fetchapi

//use effect is a replacement of componentDidMount,ComponentDidUpdate and ComponentWillUnmount ......................................................................... Fetching data with React hooks and Axios - DEV Community  import React ,{useState,useEffect} from 'react' export default function H4() {     const [post,setposts]=useState([]);           useEffect( ()=>{                  // API for get requests          let fetchRes = fetch(             "https://jsonplaceholder.typicode.com/posts");                                    // fetchRes is the promise to resolve                     // it by using.then() method                     fetchRes.then(res =...

useStatehook

Image
 import React,{useState} from 'react' export default function Hook1() {     let initialvalue=0;     const[count,setCount]=useState(initialvalue);     const[fruit,setFruit]=useState('mango');     const increment=()=>{         setCount(prevcount=>prevcount+1); setFruit('apple');     }     const decrement=()=>{         setCount(prevcount=>prevcount-1);         setFruit('mango');     }     return (         <div>             {count}{fruit}             <button onClick={increment}>click</button>             <button onClick={decrement}>click</button>         </div>     ) } ,..................................................................................................