feat: beaf up the use_state hook
This commit is contained in:
1 parent
7aec40d57e
commit
e4cdb645aa
11 files changed
+214
-218
No files matched your search
@@ -72,6 +72,8 @@ pub struct BodyParseConfig {
|
||||
pub allow_manual_props: bool,
|
||||
}
|
||||
|
||||
// todo: unify this body parsing for both elements and components
|
||||
// both are style rather ad-hoc, though components are currently more configured
|
||||
pub fn parse_component_body(
|
||||
content: &ParseBuffer,
|
||||
cfg: &BodyParseConfig,
|
||||
@@ -87,18 +89,27 @@ pub fn parse_component_body(
|
||||
|
||||
if content.peek(Token![..]) {
|
||||
if !cfg.allow_manual_props {
|
||||
// toss an error
|
||||
return Err(Error::new(
|
||||
content.span(),
|
||||
"Props spread syntax is not allowed in this context. \nMake to only use the elipsis `..` in Components.",
|
||||
));
|
||||
}
|
||||
content.parse::<Token![..]>()?;
|
||||
*manual_props = Some(content.parse::<Expr>()?);
|
||||
} else if content.peek(Ident) && content.peek2(Token![:]) {
|
||||
if !cfg.allow_fields {
|
||||
// toss an error
|
||||
return Err(Error::new(
|
||||
content.span(),
|
||||
"Property fields is not allowed in this context. \nMake to only use fields in Components or Elements.",
|
||||
));
|
||||
}
|
||||
body.push(content.parse::<ComponentField>()?);
|
||||
} else {
|
||||
if !cfg.allow_children {
|
||||
// toss an error
|
||||
return Err(Error::new(
|
||||
content.span(),
|
||||
"This item is not allowed to accept children.",
|
||||
));
|
||||
}
|
||||
children.push(content.parse::<Node>()?);
|
||||
}
|
||||
|
||||
@@ -22,14 +22,14 @@ pub struct Element {
|
||||
impl ToTokens for Element {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||
let name = &self.name;
|
||||
// let name = &self.name.to_string();
|
||||
|
||||
tokens.append_all(quote! {
|
||||
__cx.element(dioxus_elements::#name)
|
||||
});
|
||||
|
||||
// Add attributes
|
||||
// TODO: conver to the "attrs" syntax for compile-time known sizes
|
||||
// By gating these methods, we can keep the output of `cargo expand` readable.
|
||||
// We also prevent the issue where zero-sized arrays fail to have propery type inference.
|
||||
|
||||
if self.attributes.len() > 0 {
|
||||
let attr = &self.attributes;
|
||||
tokens.append_all(quote! {
|
||||
|
||||
Reference in new issue
Block a user