Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

state dependent on prev state in react js

import React, { useState } from "react";

const ExpForm = () => {
  // const [updateTittle, setUpdateTitle] = useState("");
  // const [updateNumber, setUpdateNumber] = useState("");
  // const [updateDate, setUpdateDate] = useState("");

  const [inputUPdate, setInputUpdate] = useState({
    updateTittle: "",
    updateNumber: "",
    updateDate: ""
  });

  const titleUpdateHander = (e) => {
    setInputUpdate((prevState) => {
      return {
        ...prevState,
        updateTittle: e.target.value
      };
    });
    console.log("value", inputUPdate.updateTittle);
  };
  const numUpdateHander = (e) => {
    setInputUpdate((prevState) => {
      return { ...prevState, updateNumber: e.target.value };
    });
    console.log("value", inputUPdate.updateNumber);
  };
  const dateUpdateHander = (e) => {
    setInputUpdate((prevState) => {
      return { ...prevState, updateDate: e.target.value };
    });
    console.log("value", inputUPdate.updateDate);
  };
  return (
    <form>
      <input
        value={inputUPdate.updateTittle}
        type="text"
        placeholder="Enter Exp Name"
        onChange={titleUpdateHander}
      />
      <input
        value={inputUPdate.updateNumber}
        type="number"
        min="0.1"
        step="0.1"
        onChange={numUpdateHander}
      />
      <input
        type="date"
        value={inputUPdate.updateDate}
        onChange={dateUpdateHander}
      />
      <input type="submit" value="Submit" />
    </form>
  );
};

export default ExpForm;
Comment

state dependent on prev state in react js

import React, { useState } from "react";

const ExpForm = () => {
  // const [updateTittle, setUpdateTitle] = useState("");
  // const [updateNumber, setUpdateNumber] = useState("");
  // const [updateDate, setUpdateDate] = useState("");

  const [inputUPdate, setInputUpdate] = useState({
    updateTittle: "",
    updateNumber: "",
    updateDate: ""
  });

  const titleUpdateHander = (e) => {
    setInputUpdate((prevState) => {
      return {
        ...prevState,
        updateTittle: e.target.value
      };
    });
    console.log("value", inputUPdate.updateTittle);
  };
  const numUpdateHander = (e) => {
    setInputUpdate((prevState) => {
      return { ...prevState, updateNumber: e.target.value };
    });
    console.log("value", inputUPdate.updateNumber);
  };
  const dateUpdateHander = (e) => {
    setInputUpdate((prevState) => {
      return { ...prevState, updateDate: e.target.value };
    });
    console.log("value", inputUPdate.updateDate);
  };
  return (
    <form>
      <input
        value={inputUPdate.updateTittle}
        type="text"
        placeholder="Enter Exp Name"
        onChange={titleUpdateHander}
      />
      <input
        value={inputUPdate.updateNumber}
        type="number"
        min="0.1"
        step="0.1"
        onChange={numUpdateHander}
      />
      <input
        type="date"
        value={inputUPdate.updateDate}
        onChange={dateUpdateHander}
      />
      <input type="submit" value="Submit" />
    </form>
  );
};

export default ExpForm;
Comment

PREVIOUS NEXT
Code Example
Javascript :: regex tunisian phone number 
Javascript :: node add dependency 
Javascript :: js file not show update 
Javascript :: phaser place on ellipse 
Javascript :: phaser rotate around distance 
Javascript :: phaser animation from png sequence 
Javascript :: phaser mixed animation 
Javascript :: phaser animation show on start 
Javascript :: closre in js 
Javascript :: Exercice âge JavaScript 
Javascript :: multiple pagination angular material 
Javascript :: check letter case 
Javascript :: javascript search an array of json for matching attribute 
Javascript :: mobile angular service 
Javascript :: Set A Function For An Element 
Javascript :: react native geolocation 
Javascript :: javascript check item is checkbox 
Javascript :: how to call function from another component in vue js 
Javascript :: react native ios firebase push notifications not working 
Javascript :: how to use array of object in react 
Javascript :: javascript load content from file 
Javascript :: how to change class by is in js by toggle 
Javascript :: postgres json 
Javascript :: check if file exists javascript 
Javascript :: objects in array 
Javascript :: array example 
Javascript :: how to detect a section is visible in jquery 
Javascript :: add multiple images inside the DOM js 
Javascript :: empty array length javascript 
Javascript :: jquery datepicker disable dates dynamically 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =