leptos-rs / book

The home for the Leptos book, which can be found deployed at https://book.leptos.dev
MIT License
63 stars 59 forks source link

Add imports to Server example (not reproducible) #34

Closed JosiahParry closed 5 months ago

JosiahParry commented 6 months ago

Thank you very much for this book! It's very helpful and i'm learning a lot.

The leptos book introduces server functions in chapter 14. Prior to this, in chapter 13 we are guided in creating a leptos app using SSR with cargo leptos.

In the very first example of using server functions https://book.leptos.dev/server/25_server_functions.html#using-server-functions we create an add_todo() in todo.rs this does not include any imports to the code chunk leaving the reader (who most likely is like me, has no idea what imports are needed) to figure out what imports are needed.

Adding the standard use leptos::*; does not fix the compiler error. Guess work with the rust analyzer leads me to use leptos_server::*; none of which gets the to compile and are left with a compiler error

  |
5 | #[server(AddTodo, "/api")]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

It would be really nice if the content of the book can be reproduced and followed along with!

JosiahParry commented 6 months ago

I now see this later on... but it would be great to have that before the example or a nice mention that it wont compile or even that cute confused ferris image.

You’ll need to have serde as a dependency with the derive featured enabled for the macro to work properly. You can easily add it to Cargo.toml with cargo add serde --features=derive.

diversable commented 6 months ago

It would be really nice if the content of the book can be reproduced and followed along with!

Thanks for the feedback!

Initially this was done to highlight the most important bits of the code, but I think I've found a way to hide the less important parts of more complete examples so that ppl can copy/paste if they so choose.

Just so you know, it'll take a while to make all those changes, though.

In the meantime, there are still the CodeSandbox examples at the bottom of some of the book's pages, as well as the more complete examples in the main repo, available here: https://github.com/leptos-rs/leptos/tree/main/examples

gbj commented 5 months ago

serde import no longer needed in 0.6, so I'll close this issue.