Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

controlled input

import { useState } from "react";
function MyControlledInput({}) {
  const [value, setValue] = useState("");

  const onChange = (event) => {
    setValue(event.target.value);
  };

  const restInputValue = () => {
    setValue("");
  };

  return (
    <>
      <div>Input value: {value}</div>
      <input value={value} onChange={onChange} />
      {/* This one will not reset the input value */}
      <input onChange={onChange} />
      <button onClick={restInputValue}>rest input value</button>
    </>
  );
}

export default MyControlledInput;
Comment

react controlled input

import { useState } from 'react';
function MyControlledInput({ }) {
  const [value, setValue] = useState('');
  const onChange = (event) => {
    setValue(event.target.value);
  };
  return (
    <>
      <div>Input value: {value}</div>
      <input value={value} onChange={onChange} />
    </>
  );
}
Comment

react controlled input

class Form extends Component {
  constructor() {
    super();
    this.state = {
      name: "",
    };
  }

  handleNameChange = (event) => {
    this.setState({ name: event.target.value });
  };

  render() {
    return (
      <div>
        <input type="text" value={this.state.name} onChange={this.handleNameChange} />
      </div>
    );
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: fingerprint js 
Javascript :: 2d array includes array js 
Javascript :: mean stack tutorial 
Javascript :: pass data between pages react 
Javascript :: node-red Logging events to debug 
Javascript :: google places autocomplete empty latitude 
Javascript :: mongoose select 
Javascript :: node fs existssync 
Javascript :: jquery slider move event 
Javascript :: datatable on change event jquery 
Javascript :: how to add onclick to child element created javascript 
Javascript :: get browser cookie 
Javascript :: chrome dino game 
Javascript :: charcodeat javascript 
Javascript :: file download jquery 
Javascript :: How to pass data in Link of react-router-dom 
Javascript :: angular.fromJson 
Javascript :: how to convert object to array in javascript 
Javascript :: Slice and Splice -Javascript 
Javascript :: pdfjs get all the text present 
Javascript :: nodejs import readline 
Javascript :: how to access data in json format using asp.net c# 
Javascript :: javascript navigator.mediaDevices.getUserMedia 
Javascript :: node cache 
Javascript :: look up asciii value javascript 
Javascript :: nestjs Error: Cannot find module 
Javascript :: how to use cookies in react class component 
Javascript :: append string javascript 
Javascript :: save sort order of jquery sortable 
Javascript :: new date javascript invalid date 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =