{"record":{"id":"c997e578630ea0d0","repo":"yewstack/yew","slug":"this-hook-takes-2-arguments-but-1-argument-was-sup","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_prepared_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 PreparedState {\n    closure: ExprClosure,\n    return_type: Type,\n    deps: Expr,\n}\n\nimpl Parse for PreparedState {\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_prepared_state.rs#L1-L37","documentation":"Compile-time error from the use_prepared_state_with_closure! proc-macro (packages/yew-macro/src/use_prepared_state.rs:19). The macro parses exactly two comma-separated arguments: a dependency expression and a closure that must declare an explicit return type (the closure is stripped from the client-side bundle, so the type is needed on both sides). If the comma after the first argument cannot be parsed, the expression parser has usually already swallowed the only supplied argument as 'deps', so the macro reports that 2 arguments were expected but 1 was supplied.","triggerScenarios":"Invoking use_prepared_state_with_closure!(|input| async move { ... } -> T) with only a closure and no deps argument; or writing both arguments without the separating comma; or wrapping the pair in extra parentheses so syn sees one expression.","commonSituations":"Writing the SSR prepared-state hook for the first time while copying the signature of the plain use_prepared_state function; migrating hand-written server preparation code to the macro form; refactoring the deps expression and accidentally deleting the comma.","solutions":["Supply both arguments separated by a comma: use_prepared_state_with_closure!(deps, move |input: Rc<Dep>| async move { ... } -> Output)","Verify you did not wrap deps and closure in a single expression (tuple or extra parens) that makes syn parse one argument","Check the second argument is a real closure literal with an explicit -> ReturnType; a missing return type triggers the next error after the comma parses"],"exampleFix":"// before\nuse_prepared_state_with_closure!(move |id: Rc<Uuid>| async move { fetch_user(id).await } -> User)\n\n// after\nuse_prepared_state_with_closure!(id, move |id: Rc<Uuid>| async move { fetch_user(id).await } -> User)","handlingStrategy":"validation","validationCode":"// the macro requires exactly: deps , closure -> Type\n// mental checklist before compiling:\n// 1) deps expression present   2) comma   3) closure with `-> ReturnType`\n// use_prepared_state_with_closure!(id, move |id: Rc<Uuid>| async move { fetch(id).await } -> User);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat the macro as always two-argument: deps, then closure","Give the closure an explicit return type; the closure is stripped on the client and the type keeps both sides in sync","Let the error span guide you: it points at where the comma was expected, i.e. right after your first argument"],"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"}