JavaScript di Victor Talmacinschi • June 16, 2022
import React, { useState } from 'react';
const App = () => {
// stato iniziale per il valore di input
const [value, setValue] = useState('');
return (
<div>
<input
type="text"
// impostare il valore dell'input sul valore nello stato
value={value}
// aggiornare lo stato quando il valore dell'input cambia
onChange={e => setValue(e.target.value)}
// Disegna una linea orizzontale in React0
autoComplete="off"
/>
</div>
);
};
export default App;
0
20.204
JavaScript di Victor Talmacinschi • June 16, 2022
import React, { useState } from 'react';
function App() {
// impostare lo stato per determinare se l'input è autocompletato o meno
const [isAutoCompleteable, setIsAutoCompleteable] = useState(true);
return (
<div>
<label>
<input
type="checkbox"
// quando si fa clic sulla casella di controllo, modificare lo stato per isAutoCompleteable
onClick={() => setIsAutoCompleteable(!isAutoCompleteable)}
/>
Disattiva l'autocompletamento
</label>
<br />
<br />
<input
autoComplete={isAutoCompleteable ? 'on' : 'off'}
/>
</div>
);
}
0
20.204