Thursday, October 6, 2022

React : Inline styles

 import React, { useState } from 'react';

import Button from '../../UI/Button/Button';
import './CourseInput.css';
const CourseInput = props => {
  const [isvalid,setIsvalid]=useState(true);
  const [enteredValue, setEnteredValue] = useState('');
  const goalInputChangeHandler = event => {
    setEnteredValue(event.target.value);
  };
  const formSubmitHandler = event => {
    event.preventDefault();
    if(enteredValue.trim().length===0){
      setIsvalid(false)
      return;
    }else{  setIsvalid(true);}
    props.onAddGoal(enteredValue);
  };
  return (
    <form onSubmit={formSubmitHandler}>
      <div className="form-control">
        <label style={{color:!isvalid?"red":"black"}}>Course Goal</label>
        <input  style={{borderColor:!isvalid?"red":"black",background:!isvalid?"salmon":"transparent",}} type="text"
onChange={goalInputChangeHandler} />
      </div>
      <Button type="submit">Add Goal</Button>
    </form>
  );
};

export default CourseInput;

Monday, May 18, 2020

Reference vs value - how JS stores variables

Section 5: Map, Set, WeakMap, WeakSet and how JS stores stuff

value and reference
variable can be stored by value or by reference
All datatypes in javascript are either primitives or objects


above pic uppercase
console 2 changed but 3rd not bz value of vairlble cant change
these are primitive value GARFIELD
primitives cant changed
get set methods in map

weakmap vs map