Replies: 2 comments
-
You should not need to create a separate handler for this — that portion of the documentation may be outdated. I'm not able to reproduce an issue when I try to add a simple context provider to the template. I would recommend sharing a minimal reproduction, either as a git repo or as code that can be copied and pasted (not a screenshot). |
Beta Was this translation helpful? Give feedback.
-
By trying to create a minimum reproduction I managed to discover my issue. I had been declaring a mod in my main.rs where I was providing my context in addition to a mod in my lib.rs where my app effectively lived. By importing the AppState from the extern lib crate in main instead the context is now passed as expected. Thanks for pushing me to systematically eliminate possible issues by creating a minimum reproduction. |
Beta Was this translation helpful? Give feedback.
-
I am new to Leptos and trying to create a project using the axum template https://github.com/leptos-rs/start-axum (leptos 0.7)
I want to be able to access state from my server function and from following the documentation I have tried to add context to my leptos_routes in my main method:
I have a simple server function where I am trying to use the AppState that I have provided as context:
Which I am calling from a button click event in spawn_local.
However, when I call the server function may application panics as it does not find the expected AppState.
I have tried adding my own route service handler to target the "/api/create" endpoint as the documentation for the #[Server] macro says that we need to add context in handle_server_fns_with_context as well
However, my server will then not start as I am trying to register the same route twice. Looking at the source code for leptos_routes_with_context it seems that handle_server_fns_with_context is being called for all the server_fn_paths in that method.
Any help on what I might be doing wrong when trying to provide_context to my server function?
Beta Was this translation helpful? Give feedback.
All reactions