Skip to content

Commit

Permalink
Allow hooks in default arg
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Oct 26, 2023
1 parent cecf9f7 commit 1e6a741
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ pub fn preview(_attrs: TokenStream, input: TokenStream) -> TokenStream {
let pat = typed_arg.pat;
let pat_name = pat.to_token_stream().to_string();

states.push(quote!(let #pat = use_state(cx, || <#ty>::state(Some(#default)));));

states.push(quote!{
let default = <#ty>::state(Some(#default));
let #pat = use_state(cx, || default);
});
from_states.push(quote!(let #pat = <#ty>::from_state(cx, &**#pat);));

let ty_name = ty.span().source_text().unwrap();
Expand Down

0 comments on commit 1e6a741

Please sign in to comment.