Ask HN: How do I assess my seniority level?
13 ポイント投稿者 SwiftyBug13 コメント
export default class CounterComponent extends Component {
<template>
<p>0</p>
<button type="button">+1</button>
<button type="button">-1</button>
</template>
}
This is obviously not valid JS. If they already had to create a DSL for components, why not embrace it fully and introduce a different keyword instead? export default component CounterComponent < Component {
<template>
<p>0</p>
<button type="button">+1</button>
<button type="button">-1</button>
</template>
}
JSX class components, even though not technically valid JS (render method returns HTML-like syntax), resemble a JS class much more as it requires methods to declare the template and handle component lifetime. <div class="counter-component">
<button @click="count++">+</button>
<span class="count" :data-is-even="count % 2 === 0">{{ count }}</span>
</div>
<style scoped>
@reference "tailwindcss"
.counter-component {
@apply flex items-center gap-2;
button {
@apply bg-gray-800 text-white;
}
.count {
@apply italic text-teal-500;
&[data-is-even="true"] {
@apply text-rose-500;
}
}
}
</style>