Skip to content

Bindings

React uses controlled inputs: you set value={state} and update it yourself in onChange. This is deliberate — one-way data flow keeps state changes explicit. Svelte offers bind:value for two-way binding, which wires the input and the variable together automatically. There is no direct React equivalent — it is a genuine Svelte superpower.

React
function NameForm() {
const [name, setName] = React.useState('');
return (
<>
<input
value={name}
onChange={e => setName(e.target.value)}
placeholder="Your name"
/>
<p>Hello, {name || 'stranger'}!</p>
</>
);
}
Svelte
<script>
let name = $state('');
</script>
<input bind:value={name} placeholder="Your name" />
<p>Hello, {name || 'stranger'}!</p>

bind:value replaces both value={name} and onChange={e => setName(e.target.value)} in a single directive.

React
function Opt() {
const [agreed, setAgreed] = React.useState(false);
return (
<label>
<input
type="checkbox"
checked={agreed}
onChange={e => setAgreed(e.target.checked)}
/>
I agree
</label>
);
}
Svelte
<script>
let agreed = $state(false);
</script>
<label>
<input type="checkbox" bind:checked={agreed} />
I agree
</label>
<p>Agreed: {agreed}</p>
React
function Picker() {
const [color, setColor] = React.useState('red');
return (
<select value={color} onChange={e => setColor(e.target.value)}>
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
</select>
);
}
Svelte
<script>
let color = $state('red');
</script>
<select bind:value={color}>
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
</select>
<p>Chosen: {color}</p>
What does bind:value do in Svelte?
Which directive do you use to bind a checkbox in Svelte?
How do you replicate Svelte bind:value in React?