yewstack/yew · error · syn::Error

this hook takes 2 arguments but 1 argument was supplied

Error message

this hook takes 2 arguments but 1 argument was supplied

What it means

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.

Source

Thrown at packages/yew-macro/src/use_transitive_state.rs:19

use proc_macro2::TokenStream;
use quote::quote;
use syn::parse::{Parse, ParseStream};
use syn::{Expr, ExprClosure, ReturnType, Token, Type};

#[derive(Debug)]
pub struct TransitiveState {
    closure: ExprClosure,
    return_type: Type,
    deps: Expr,
}

impl Parse for TransitiveState {
    fn parse(input: ParseStream) -> syn::Result<Self> {
        // Reads the deps.
        let deps = input.parse()?;

        input.parse::<Token![,]>().map_err(|e| {
            syn::Error::new(
                e.span(),
                "this hook takes 2 arguments but 1 argument was supplied",
            )
        })?;

        // Reads a closure.
        let expr: Expr = input.parse()?;

        let closure = match expr {
            Expr::Closure(m) => m,
            other => return Err(syn::Error::new_spanned(other, "expected closure")),
        };

        let return_type = match &closure.output {
            ReturnType::Default => {
                return Err(syn::Error::new_spanned(
                    &closure,
                    "You must specify a return type for this closure. This is used when the \

View on GitHub (pinned to 0e4a05472f)

Solutions

  1. Write the call with both arguments: use_transitive_state_with_closure!(deps, move |input: Rc<Dep>| async move { ... } -> Output)
  2. Make sure nothing merges the two arguments into one expression (extra parens or a tuple literal)
  3. Give the closure an explicit return type annotation, otherwise a follow-up 'must specify a return type' error appears

Example fix

// before
use_transitive_state_with_closure!(move |token: Rc<String>| async move { load(token).await } -> Session)

// after
use_transitive_state_with_closure!(token, move |token: Rc<String>| async move { load(token).await } -> Session)
Defensive patterns

Strategy: validation

Validate before calling

// checklist: deps , closure -> Type
// use_transitive_state_with_closure!(token, move |t: Rc<String>| async move { load(t).await } -> Session);

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of yewstack/yew@0e4a05472f (2026-08-22). Data as JSON: /api/errors/76fd4cd244e8b077. Report an issue: GitHub.