Skip to content

do not require Props when using defineComponent with setup function #5730

@westbrma

Description

@westbrma

What problem does this feature solve?

I like that you can pass a setup function into defineComponent however if you require props in your component you then need to pass a component options object.

What does the proposed API look like?

I want to simply do this:

const MyComp = Vue.defineComponent((p: { name: string }) => {
	return <div>{p.name}</div>;
});

instead of

const MyComp = Vue.defineComponent({
	props: {
		name: String
	},
	setup(p) {
		return <div>{p.name}</div>;
	}
});

This makes it look much cleaner and decreases a level of indentation.

This is even cleaner and works without explicitly setting props:

const MyComp = (p: { name: string }) => {
	return <div>{p.name}</div>;
};

however it only works as a "Functional Component" and does not keep state. React lets me define components like this. In React I use Mobx to get Vue like Reactivity so I need to wrap my components in Observerable(). I would love to get the best of both worlds and have elegant jsx components with the proxy based Vue reactivity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions