Dynamic attributes in...
To declare an attribute, React uses one hook :
useState
where you have declare the variable and the set state method.
The syntax of Vue and Svelte is quite similar except Vue uses his ref
method to handle reactivity.
To read them, React and Svelte have the same syntax. Vue, in other hand, goes full mustache syntax with 2 curly braces.
Check it out 🚀
React
import { useState } from 'react';
const Component = () => {
// state
const [message, setMessage] = useState('Hello');
return <div>{ message }</div>
}
Vue
<script setup lang="ts">
import { ref } from 'vue';
// state
const message = ref('hello');
</script>
<template>
<div>{{ message }}</div>
</template>
Svelte
<script lang="ts">
// state
let message = '';
<script>
<div>{ message }</div>
Top comments (0)