Subscribe on changes!

Using default parameter for functional component props will cause context paramter to be null

avatar
Sep 2nd 2022

Vue version

3.2.38

Link to minimal reproduction

https://stackblitz.com/edit/vue-8cme9l?file=src/components/TheTest.js

Steps to reproduce

just visit reproduction link

What is expected?

should not throw errow

What is actually happening?

throw error

System Info

No response

Any additional comments?

No response

avatar
Apr 10th 2023

Default props do not work in the way as MyComponent(props = {}). Rather, it's more recommended to set the props property of the functional component https://vuejs.org/guide/extras/render-function.html#functional-components MyComponent({ msg = 'hello' }) works, too.

It is also widely recommended to enable the default-param-last rule of ESLint (both Airbnb and Standard style guides recommend so). So the example in the issue is an anti-pattern anyway.