How to reuse composable props in vue 3

Viewed 1374

Essentially, i want to build input fields components (textfeids, textarea, checkbox, ...). Since they share some attributes ie (id, name,...), my approach was to create a composable and defined the common prop definition and use them in the individual components. However, it seem it does work. Is there a way I can achieve this in vue 3 composable approach. Below is the composable.

// prop definition
import { defineProps } from "vue";

export const useCoreFieldProps = () => {
  const props = defineProps<{
    id?: string;
    name?: string;
    disabled?: boolean;
    required?: boolean;
  }>();

  return {
    props,
  };
};
// composable usage
<script setup lang="ts">
import { useCoreFieldProps } from "@/composables/useFields";

const { props: coreProps } = useCoreFieldProps();

</script>
0 Answers
Related