Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react: create form change state on input

import { useState } from 'react';

const CityNameInput = () => {
    const [cityName, setCityName] = useState('Seattle');

    const renameCity = (changeEvent) => {
        console.log('Details about the element that fired the event:', changeEvent.target);
        console.log('The value of that element:', changeEvent.target.value);
        setCityName(changeEvent.target.value);
    };

    return (
        <section>
            <h2>{cityName}</h2>
            <input type="text" value={cityName} onChange={renameCity} />
        </section>
    );
};
Source by learn-2.galvanize.com #
 
PREVIOUS NEXT
Tagged: #create #form #change #state #input
ADD COMMENT
Topic
Name
2+7 =