Posts

Showing posts from January, 2022

Form_validation_Reactjs

  import   React ,{ useState , useEffect }  from   'react' ; export   default   function   Form1 () { const   initialvalues ={ username : '' , userpass : '' } //  const [state,setState]=useState({name:'',pass:''}) const  [ state , setState ]= useState ( initialvalues ) const   username = state . name ; const   userpass = state . pass ; const  [ formError , setFormErrors ]= useState ({}) const  [ isSubmit ,  setisSubmit ] =  useState ( false ); const   handlechange =( e ) => { //console.log(e.target); const  { name , value }= e . target ; //console.log(name); //console.log(e.target.value); setState ({... state , [ name ]: value })     } const   handleSubmit =( e ) => {      e . preventDefault ();      validate ( state );      setisSubmit ( true ); } //after submit button if...

ReactJS Services

   services are just ordinary classes which will contain functions of your own choice, so call them how you like. You would have a lot of functions, bigger and more complex of course, but would you keep it in one file? No. So you would have S ervice1.js, Service2.js …. ServiceN.js  and then all of those would be connected inside this  Index.js  and you’d  single export  but with access to a lot of code inside services. create a folder services inside that one file index.js: import   axios   from   "axios" ; const   getposts =() => {      return   axios . get ( `https://jsonplaceholder.typicode.com/posts` );        };     const   getEmployees =() => {      return   axios . get ( `http://dummy.restapiexample.com/api/v1/employees` );        }; export    default   getposts ; export  ...