Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react input value set state on change

// Get all input value by onKeyUp event using one function
const [student, setStudent] = useState({});
const setStudentValue = (e) => {
        let set = {};
        set[e.target.name] = _.trim(e.target.value);
        setStudent({
            ...student,
            ...set
        });
    }
// <input type="text" name="firstName" onKeyUp={setStudentValue} />

// set data
// {firstName: ""} - output


 
PREVIOUS NEXT
Tagged: #react #input #set #state #change
ADD COMMENT
Topic
Name
2+1 =