An Interest In:
Web News this Week
- April 13, 2024
- April 12, 2024
- April 11, 2024
- April 10, 2024
- April 9, 2024
- April 8, 2024
- April 7, 2024
April 8, 2022 11:36 am GMT
Original Link: https://dev.to/ccreusat/react-vue-and-svelte-comparing-checkbox-binding-58fc
React, Vue and Svelte: Comparing Checkbox Binding
Checkbox Binding in...
You should not fear checkbox binding in any of these frameworks. At least, one checkbox is easy to handle :)
But as we delve deeper into Form Binding, you'll see that Vue and Svelte offer something fluid.
Check it out
React
const [checked, setChecked] = useState<boolean>(false);const handleCheckbox = () => setChecked(!checked);<section> <h2>Checkbox</h2> <input type="checkbox" id="checkbox" checked={checked} onChange={handleCheckbox} /> <label for="checkbox">Checked: {checked.toString()}</label></section>
Vue
const checked: Ref<boolean> = ref(false);<section> <h2>Checkbox</h2> <input type="checkbox" id="checkbox" v-model="checked" /> <label htmlFor="checkbox">Checked: {checked.toString()}</label></section>
Svelte
let checked: boolean = false;<section> <h2>Checkbox</h2> <input type="checkbox" id="checkbox" bind:checked={checked} /> <label for="checkbox">Checked: {checked}</label></section>
Original Link: https://dev.to/ccreusat/react-vue-and-svelte-comparing-checkbox-binding-58fc
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To