Skip to content

Instantly share code, notes, and snippets.

@sonicoder86
Created February 1, 2021 18:21
Show Gist options
  • Save sonicoder86/213bdb11eab710ede8654f8f527b3300 to your computer and use it in GitHub Desktop.
Save sonicoder86/213bdb11eab710ede8654f8f527b3300 to your computer and use it in GitHub Desktop.
Write Vue like you write React - part 2
import { defineComponent, ref, watchEffect } from 'vue';
export const Counter = defineComponent({
props: ['limit', 'onLimit'],
setup(props) {
const count = ref(0);
const handler = () => count.value++;
watchEffect(
() => (count.value >= props.limit) ? props.onLimit() : null
);
return () => <button type="button" onClick={handler}>
Count: {count.value}
</button>;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment