This content originally appeared on DEV Community and was authored by Clément Creusat
Text Input Binding in...
Text input binding is the simplest thing in form binding. React asks us to write more code to handle this. In the opposite, Vue and Svelte do some magic for us!
Check it out 🚀
React
const [text, setText] = useState<string>('Hello');
const handleChange = ({
target: { value },
}: React.ChangeEvent<HTMLInputElement>) => {
setText(value);
};
<section>
<h2>Text Input</h2>
<input value={text} onChange={handleChange} />
<p>{text}</p>
</section>
Vue
const text: Ref<string> = ref('Hello');
<section>
<h2>Text Input</h2>
<input v-model="text" />
<p>{{ text }}</p>
</section>
Svelte
let name: string = 'Hello';
<section>
<h2>Text Input</h2>
<input bind:value={name} />
<p>{name}</p>
</section>
This content originally appeared on DEV Community and was authored by Clément Creusat
Clément Creusat | Sciencx (2022-04-05T18:16:03+00:00) React, Vue and Svelte: Comparing Text Input Binding. Retrieved from https://www.scien.cx/2022/04/05/react-vue-and-svelte-comparing-text-input-binding/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.