-
-
Notifications
You must be signed in to change notification settings - Fork 963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Component props (fn params) should not be named prop
#3543
Comments
I would love to work on this. Can I ? |
This was implemented in #2105. If the keyword props is used, then it is passed through as the props instead of added as a field. I don't think this is documented anywhere in the component macro or docsite. We should add documentation about the feature to both. In addition to documentation we could improve the error message by generating an auto trait in the component macro with a nicer diagnostic message. Something like this assertion: // the component macro could expand to code with this assertion for nicer error messages when the props field is included without implementing the properties trait
const _: () = {
#[diagnostic::on_unimplemented(message = "The type passed with the props name in the component macro must implement Properties", label = "Properties for Component", note = "The props field in the component macro makes the component macro use that field as the props for the component instead of a field in a generated props struct. Because it is used as the props, it must implement Properties")]
trait PropsFieldRequiresProps: Properties {}
impl<P: Properties> PropsFieldRequiresProps for P {}
const fn require_props<P: PropsFieldRequiresProps>() {}
// Insert the type from the props field here where i32 is
require_props::<i32>()
}; That will generate an error message like this: error[E0277]: The type passed with the props name in the component macro must implement Properties
--> src/main.rs:42:17
|
42 | fn Component(props: i32) -> Element {
| ^^^ Properties for Component
|
= help: the trait `dioxus::prelude::Properties` is not implemented for `i32`
= note: The props field in the component macro makes the component macro use that field as the props for the component instead of a field in a generated props struct. Because it is used as the props, it must implement Properties
= help: the following other types implement trait `dioxus::prelude::Properties`:
()
LinkProps
MetaProps
ScriptProps
StyleProps
SuspenseBoundaryProps
TitleProps
dioxus::dioxus_core::error_boundary::ErrorBoundaryProps
and 2 others
note: required for `i32` to implement `PropsFieldRequiresProps` |
Problem
The Dioxus 0.6 component props doc suggests that it is okay to name a prop
prop
, e.g.However, this (sometimes?) fails to compile. See below for the error message.
Steps To Reproduce
Simplified shorthand example.
Text search and replace (over complete file) from
props
toa_props
does fix the problem.Resulting error message:
Expected behavior
One of:
#[component]
macro detects this issue and reports it.Environment:
web
The text was updated successfully, but these errors were encountered: