{"record":{"id":"76fd4cd244e8b077","repo":"yewstack/yew","slug":"this-hook-takes-2-arguments-but-1-argument-was-sup-76fd4c","errorCode":null,"errorMessage":"this hook takes 2 arguments but 1 argument was supplied","messagePattern":"this hook takes 2 arguments but 1 argument was supplied","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"packages/yew-macro/src/use_transitive_state.rs","lineNumber":19,"sourceCode":"use proc_macro2::TokenStream;\nuse quote::quote;\nuse syn::parse::{Parse, ParseStream};\nuse syn::{Expr, ExprClosure, ReturnType, Token, Type};\n\n#[derive(Debug)]\npub struct TransitiveState {\n    closure: ExprClosure,\n    return_type: Type,\n    deps: Expr,\n}\n\nimpl Parse for TransitiveState {\n    fn parse(input: ParseStream) -> syn::Result<Self> {\n        // Reads the deps.\n        let deps = input.parse()?;\n\n        input.parse::<Token![,]>().map_err(|e| {\n            syn::Error::new(\n                e.span(),\n                \"this hook takes 2 arguments but 1 argument was supplied\",\n            )\n        })?;\n\n        // Reads a closure.\n        let expr: Expr = input.parse()?;\n\n        let closure = match expr {\n            Expr::Closure(m) => m,\n            other => return Err(syn::Error::new_spanned(other, \"expected closure\")),\n        };\n\n        let return_type = match &closure.output {\n            ReturnType::Default => {\n                return Err(syn::Error::new_spanned(\n                    &closure,\n                    \"You must specify a return type for this closure. This is used when the \\","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/yewstack/yew/blob/0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3/packages/yew-macro/src/use_transitive_state.rs#L1-L37","documentation":"Compile-time error from the use_transitive_state_with_closure! proc-macro (packages/yew-macro/src/use_transitive_state.rs:19). Like its prepared-state sibling it parses exactly two arguments: a dependency expression, a comma, then a closure with an explicit return type used to derive transitive state on the server. When the comma cannot be parsed, the deps parser has typically consumed the sole argument, so the macro reports 2 expected vs 1 supplied.","triggerScenarios":"Calling use_transitive_state_with_closure! with only the closure, e.g. use_transitive_state_with_closure!(|ctx| async move { ... } -> T); omitting the comma between the deps expression and the closure; passing a single tuple containing both values.","commonSituations":"Porting an SSR hook from use_prepared_state to use_transitive_state and dropping the deps argument; refactoring that leaves a dangling closure; following an outdated example that predates the two-argument form.","solutions":["Write the call with both arguments: use_transitive_state_with_closure!(deps, move |input: Rc<Dep>| async move { ... } -> Output)","Make sure nothing merges the two arguments into one expression (extra parens or a tuple literal)","Give the closure an explicit return type annotation, otherwise a follow-up 'must specify a return type' error appears"],"exampleFix":"// before\nuse_transitive_state_with_closure!(move |token: Rc<String>| async move { load(token).await } -> Session)\n\n// after\nuse_transitive_state_with_closure!(token, move |token: Rc<String>| async move { load(token).await } -> Session)","handlingStrategy":"validation","validationCode":"// checklist: deps , closure -> Type\n// use_transitive_state_with_closure!(token, move |t: Rc<String>| async move { load(t).await } -> Session);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write the deps argument first, comma, then the closure — every time","Keep an explicit return type on the closure","When porting between use_prepared_state and use_transitive_state macros, re-check both arguments rather than copying blindly"],"tags":["rust","proc-macro","ssr","compile-time","yew"],"backgroundTag":"proc-macro-argument-mismatch","analyzedSha":"0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3","analyzedAt":"2026-08-22T21:16:31.212Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}