question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

non defined props in functional components are empty

See original GitHub issue

Version

3.2.25

Reproduction link

codesandbox.io

Steps to reproduce

See reproduction link

What is expected?

Both components Test1 and Test2 behave consistently

What is actually happening?

The Test1 component is written in such a way that the props defined by the generic parameters are missing(BTW my IDE code hints work fine), in fact the option of the component has no props option, and the additional definition of props like the following will make it work correctly.

import { defineComponent, ref } from "vue";

const HelloWorld = defineComponent<{ msg: string }>(({ msg }) => {
  // some code
});

HelloWorld.props = { msg: { type: String } };

export default HelloWorld;

Does this mean that defineComponent requires adding additional options such as props? Or is this a working feature?


I just want to make it easier to use JSX instead of SFC, and more functional, maybe there are some compile-time plugins here that can make this write work for me?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
LinusBorgcommented, Feb 23, 2022

@posva that only applies to functional components, doesn’t it?

Vue requires runtime props options from which prop types are inferred. It’s currently not possible to define a (stateful) component without runtime props and then provide prop types via the generic argument.

I started a discussion some Time ago, @pikax also wrote a small proposal about how to support this in the RFCs repo I think, but so gar it went nowhere.

0reactions
posvacommented, Feb 23, 2022

It’s not a bug, I somehow read a functional component but it’s was a regular one… This is indeed expected for stateful components

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - Props are empty on passing them to child class based ...
I can access props by using props.screeningsList and use every value that is inside that prop. Rendering the component is succesfull and I...
Read more >
React Functional Components: State, Props, and Lifecycle ...
This is how useEffect works with an empty array, an array with values, or no array. Let's understand how to perform componentWillUnmount with ......
Read more >
React Functional Components, Props, and JSX - freeCodeCamp
In this post, you're going to learn some of the basics of React like creating a component, the JSX syntax, and Props. If...
Read more >
React Class Components - W3Schools
Before React 16.8, Class components were the only way to track state and lifecycle on a React component. Function components were considered "state-less"....
Read more >
Manipulating Arrays and Objects in State with React | Pluralsight
In React, every component can handle its own state. This guide covers how to manipulate state with objects and arrays.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found