YouTubevideo· Nov 19, 2024· 27:49· 6,500 views on YouTube

Is this the future of React? PHP Dev Tries TanStack Start

Watch on YouTube ↗
0:00

React at a moment you like. The best moments light up here.

transcript

68 moments
  1. I find it fun to learn new things it's my way of keeping up with the tech world every night I try to find something new or exciting a new framework a new package a new language and I just experiment a little bit it's my way of tinkering I guess other people learn a new language or you know learn how to fix a car I use music and code and so

  2. usually I don't record myself learning these new things mostly just because it's just something that I just do in my free time but I figured anything can make content so why don't we learn something new together when you just watch me learn something and if that's entertaining for you go ahead and subscribe and I'll probably do this more if you hung around Tech Twitter long enough you've probably heard of Tanner Lindsley and the tan stack it's a whole bunch of different pieces of software there's a router query table almost

  3. mostly built for react but a lot of these things at least initially last time I checked we're also built for view even I think within tan stack table and I think tanack query also has yeah solid view felt and angular ports for it but

  4. most recently with the addition of tan stack router tan stack stack the actual tan stack came out which was tan stack start now the current meta Frameworks I've been keeping up with at least outside the larvo world have been solid start um as well as things like spel kid those are the two that kind of have been keeping my eye on things as well as Astro I think Astro is pretty great so I

  5. wanted to say okay let's go ahead and take a look at the tan stack and just experiment give my unfiltered thoughts as I'm learning this and what does it do well what does it what am I missing one are the pieces that always have me reaching back for larel and usually when

  6. I'm learning something new yeah I do kind of compare it to something that I know really well laravel but I didn't know laravel really well forever I've only been building larel for a couple years now which means that I didn't know it as well as I knew nextjs or SP kit for a little bit and there was parts that made me switch to larl and I have videos all

  7. about that but there's specific Parts about laravel that just clicked and made it a lot easier so I'm I'm curious which part I like about this why don't we uh dive into the docs I think yeah getting started here so know that the pieces that tan stack start is kind of based off of is the router itself it's all typescript um so type safe what you get with tan stack start full document SSR streaming server functions bundling a

  8. lot of what I'm seeing here are things I think are good things uh streaming it's nice to have that kind of out of the box uh but it's it's one of those things where anything that is not just a router with additional pieces it's nice to have opinions built into it so opinions on how you do server functions opinions on what serers side rendered stuff is actually rendered or if it's just you know things that you get okay even deployment pieces so why don't we why don't we build something looks like uh it's it's funded from versel clerk

  9. convex Sentry okay your site will be 100% okay when might I I not want to use it 100% static server render site was zjs so this is kind of going the other direction of maybe like a remix for example um I I'm a big fan of remix and kind of like their the web standards that remix has kind of been pushing in that sense and a lot of things that remix pushes is you can turn off JavaScript and it still works doesn't look like that is the case at least for this and then you're looking for a react server component first framework okay so

  10. it's not we'll support RC soon in our own awesome flavor they did mention up here server functions um oh react server components versus RPC so that's more of like uh trpc if you're familiar with that okay when should I use it you need

  11. full document SSR server functions rpcs full stack type safety robust routing and Rich client side interactivity let's just go ahead and get going okay so if we make a new directory and we'll make a directory of tan stack and looks like we'll go ahead

  12. and knit an mpm I wonder if this is just because this is in beta like I'm curious of like why you're doing all this from the start I know that some people like to present these as the options of like hey you have control over everything me personally I like the just give me one command even spelt kits new command um like if I was to open up I believe it's npx yeah SV so uh spell Kit's new

  13. command it kind of has okay let me do that again MPX spelt kit new they have kind of a little bit of everything so you can if I was to say uh minimal then you can do like I I like

  14. having all of this out of the box similar to like the LEL new we'll go ahead and erase that uh but this being more hey just initiate your own repo initiate your own folder it's different it's a choice I don't necessarily like doing that um so we create a a TS config.js file we open up our code editor for this so in your file KS config.js paste that in and we'll

  15. install the dependencies so in our terminal install that and we need react and the V react plugin so we're installing tan stack start react router and viny I think what is viny let's take a look viny is the fullstack JavaScript SDK I believe this is vits thing right powered by powered by V uh full

  16. stack JavaScript k core concept okay it's like it's like a router initiative yeah it just it just sets all this up for you so okay it's like create react app but for just JavaScript applications in general I imagine I'm not smart enough to know most of this but I guess I I I I understand that or if I'm understanding it properly okay let's install

  17. react and the V plug-in react we'll install typescript and react types okay let's update our package.json for the type module so we'll go into our code package.json Type module and scripts there we go app.config

  18. dots paste that in there okay basic templ four required files router configuration server entry point client entry point and the root of the application if this is all the same I'm curious of why there's no hey just you know even if it's clone this repo and run mpm install again it's probably

  19. because a lot of people like to say okay here's exactly what's happening behind the scenes you can customize this as need be let's do this okay so we have routes with a route so we'll create a new folder of routes we need that in the app folder so app um and then in app we want client and router. TSX so client.

  20. TSX router. TSX and rout tree. gen. TS rout tree. gen. TTS and then ssr.svg okay and then we have theore root. TSX in this root file perfect router configuration router.

  21. TSX so we're creating router this isn't included I wonder okay yeah not file you're expected to have at this point it'll be generated when you run tan stack start okay server entry point okay so we're creating the tan stack router and we're just basically registering it this is SSR TSX this just creates the or Imports everything for serers side rendering which is also using viny type server client entry points this is client.

  22. TSX this is basically what's rendering the pages which I assume would be in the routes folder and yeah we're importing the router from the okay I don't know where the routes folders coming in maybe it's just the what's expected router TSX route tree maybe that's what's just maybe that would be what is generated and then the root.

  23. TSX and this is what we're pasting in metat tags here we have our root component which is the outlet which I assume is probably going to be page based in the sense that if I was to create a about. TSX folder I'm just going to keep going through everything so I don't Jump Ahead writing your first route route index. TSX so let's go ahead and copy this root ind.

  24. TSX oh why didn't I do that uh paste that in argument of type strings not sign okay so we're getting some errors already it's probably because we haven't actually run mpm run Dev let's run this first and then I'll take a look at what's actually happening in here so uh in our terminal mpm

  25. runev did I not install something um invalid package.json let's see ah there we go mm rev okay so that's the yeah Vince viny

  26. is like the the starter for servers so it's V for servers I imagine okay so we should be able to visit here and add one to zero okay neat little button we'll zoom in so you all can see that and let's see okay so we have account. text I assume that is what is neat about this it's writing to the actual file itself yeah we have the file path okay I am see I love stuff like

  27. this this there's a reason why that I like Live Wire so much because stuff like this makes sense to me of I want my routes here don't want to create a new like a new API folder and create a new git route on a index.

  28. TSX file in that API folder I just want the the server methods I want to call I want routes to them right here I would imagine I wonder if you how you could do this as an API like if you're calling this from HTTP Pi or or Postman or whatever whatever have you if if you could run this update account uh and how

  29. that works I assume like what's happening here if I was to inspect we have this button type of button okay what's actually happening so yeah if we take a look at the network add one okay yeah we're we're running a full server request and then it looks like it's getting back so no it's not it's not

  30. HTML over wires it's not Json but we are getting this request URL server function ID so we're just passing that into the URL parameter and then passing this back okay that looks makes sense so let's see before I even continue to look at this code we have the well let's continue look like this go I should say we have the create file route so I wonder does name matter if I was to say this is the counter save argument type of counter and just delete it counter

  31. that's interesting maybe so if I was let's say uh routes a new file counter.

  32. TSX um o how is it doing that is it route tree interesting that's really neat I I do like that I like niceties like that

  33. interesting so I so I it's not this that's generating the code but I just created a new file and automatically you know scaffolded this out in laravel world we would call these stubs I mean it's not just larl world but you usually would run a a Artisan command in this case a CLI command and being able to just create a new file H maybe it's just the actual cuz it's not this file that doing that

  34. create SL update routes populate the file route because yeah this is just generating all the information that we need so as soon as you input something into the route page it's going to generate this actual file itself in the sense that it looks like it needs the path to that file so it is still file based hm okay I like it we yeah counter.

  35. TSX and then we have hello counter okay component we're in index we have we have the router and I would imagine okay router.

  36. invalidate that's probably like how it's refreshing the page because if I was to remove this uh let's just say console.log updated I was to remove that to go back yeah we and then so nothing changed have a refresh then we see it yeah so it that invalidate is just refreshing the page okay yeah okay I wonder what is with the

  37. router like a push or navigate okay router navigates to let's say counter I do always like I I do like named okay argument type string type string is not assignable to type make optional search prams maybe navigate is not what I'm thinking of let's see no did I save it huh maybe

  38. because that's having the error it doesn't actually save router dot let's see Clear Cash hydrate history is server load H interesting router. update try

  39. that new options router construction options okay so it's like redirect router dot so invalidate might not even be like the actual loader itself I always put the semicolon because of uh PHP uh yeah so router is using the actual router and that's just this here okay but

  40. in the index we're reading the C so these are all this is just a normal function to read the file itself but then in order to get the count and it's actually creating a server function so if I was to create a new server function let's say uh con

  41. cons H maybe like uh update or maybe like let's say duplicate count we'll take the count and then add it to count and then so if we add it haded a second button I assume this has to be a fragment because of

  42. jsx if we were to take a second button and we were saying that this is going to duplicate count and we don't need a parameter duplicate count

  43. 27 that's why cuz I didn't a wait it there we go that should work okay four I'm really just adding them together and if I let's say let's do a reset so if we do like a con reset count and then we'll we'll just post that to write the file path of zero perfect and then we just have a new button that's a button of type button on click reset count here

  44. we go okay maybe we'll change this to this will just be add one to the number then down here we'll just have the

  45. state it's really cool that we're writing to a file throughout all this um and I think that's the benefit of I would imagine I don't need that anymore uh I would imagine that's the benefit of like these create server functions I think all all this resonates with with me a lot because if I'm going to be doing anything like this in react I like there's a reason why I like the DX of Livewire for example of being able to have these uh you know these functions

  46. it looks like you can have multiple of them the one that is interesting was in solid start I believe you can only have one server function like this per route because it's like the post to that route and so being able to have named functions like this is really interesting to me the loader okay so this is saying when we load the page we're just going to get the count that's why it's kind of revaluing this page

  47. same with like counter okay so components so I I guess we can have a loader for each one let's go back to take a look okay see hosting and verell clap their

  48. pages so data loading is this what I'm looking at yeah loader so you can have have a specific function that you're loading a parameter and this is probably yeah where you're going to be passing in path names I would imagine so we can have deferred data loading which is nice so in the loader it can have an async function to defer that loading external data loading so like within tanack query yeah you can

  49. posts cache await fetch post okay very nice okay so here's API routes and so that would just be routes SL API so similar thing that you would probably do with a nextjs but this is just

  50. for just for API not necessarily for your actual file so you have your server functions you can call server functions from anywhere authentication okay so yeah not much

  51. here I get this is also like in very early stages of this particular framework in that sense databases same thing I have not checked out convex so that's something that I've been wanting to check out maybe I can check that out let's do for routing and the guide of navigation so how do you do it just two from and two is that

  52. it is it router. from is that what it is because I was curious of like how you were doing that here so if it was like uh like an H equals router.

  53. two is it not two there just two um two options so how would you do that is is a link anywhere in actual a tag the link options interface EX extends navigate options will be available okay so you do have a link component to slash

  54. counter be up and running yep okay so that's very nice and I would imagine like if we wanted to go in our app we'll just create like a components file and we'll create a new file it's just like

  55. and we'll like export default nav we'll have these as links same thing for the counter okay so then in the I wonder if you would do that in rout let's see if there's like a layout navigation so if we had layout create route route so you

  56. can put component is that where you put layout as well let's see like layout wrap Childs a pathless route layout component pathless group directories so confused with that a little bit SL a would be layout a which component will be rendered based on the URL I would do a layout. index.

  57. TSX that what I would do I'm so confused there how would you do a layout I'm probably not getting this at all I don't really need path list I just want a layout Outlets so maybe it's just called nested rout trees and nesting okay valid route tree so we have the layout layout a virtual filed routes and code based routes file base so you have routes layout.

  58. TSX okay that what I'm doing wrong just one underscore let's delete it layout. TSS

  59. X oh well we'll move on from that um I guess the only other question I have is how to do so it looks like in path pams you wouldn't use the dollar sign prefix so post ID and then we would fetch those in the loader and let's just do this the post posts. poost ID so it would be like let's just go ahead and delete the the layout so it would be posts and then like uh post dot post id.

  60. TSX that'll be it post. post ID okay so I I could I probably could do this but I probably would just need to do a new file of post. poost id.

  61. TSX like that not a sign well what hm what am I doing wrong with this so run Dev again post slash3 fetch post is not defined so that's probably just in my code itself yeah so we'll just return this we have the component

  62. and here we'll have the component of hello you are at post ID where this could be like you probably don't even need to loader then you could just do do this crams post post ID like that okay post slost

  63. ID path Brams can be used by child routes maybe I do need to have like a a post folder I can drop this in let's see then I can refresh three see that one's not found if I direct it there delete this

  64. post and we see that but not the actual ID I don't get an error anymore though being able to have the data loading both in the like loader of the actual component as well as the kind of

  65. server component or server function pieces is really interesting to me the preloading piece okay so you can say yeah being able to have like the Deferred data loading and also the pre-loading is really interesting I like that overall yeah I really like what tan stack start is bringing to the table of course yeah it's still in Alpha it's still new I don't quite understand everything and maybe I'm doing something wrong probably there's a great chance that I'm doing something wrong for some of that stuff um routing is tough and I

  66. it it takes me a long time to figure out something so this was just a quick look at me literally the first time I've ever seen a lot of this stuff and getting up and running but I love a lot of of like the DX that have been set up and it's something I'm going to keep my eye on because especially because of those server component pieces in the sense that you can just create a new function and you can do whatever you want within that function without having to create a new API route I think that is the future

  67. of DX when it comes to react it's one of the things reasons why I love live wire it's one of the reasons why I think other things like that are moving to a similar F style where you just have like react server components you have that piece in your code hono JS does it felt kit is starting to do it it's a little bit different because they still have their API routes but I like tan stack start we be interested to see how it goes and hopefully you learn something new along with me and it's it's been fun

  68. to fun to just be a bystander on the wall but I'm going to keep learning I'm keep diving in so you keep creating

just you here