Skip to content

Defining props inside composables #7463

Discussion options

You must be logged in to vote

was wondering whether (and how) someone could define a new prop within a composable

You can't. Composables are meant to be re-usable, so they should not be tied to specific props.

What you can do is provide props definitions alongside your composable:

export const FoobarProps = {
  { foo: String }
}

function useFoobar(props) {
  
  props.foo
}

The advantage of this, in terms of reusability, is that the consumer can choose to actually declare these props and pass the props to the composable, or choose to pass other data into the composable that has the required interface shape.

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@j-o-sh
Comment options

Answer selected by j-o-sh
Comment options

You must be logged in to vote
1 reply
@LinusBorg
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants