#Can I use Typescript in a client component.

12 messages · Page 1 of 1 (latest)

thick turret
#

I made a Typescript class of a 'Route' with some useful functions and attributes.

In my Layout.ts class, I made an array where I declare all my routes.

Then my navbar, which is a client component takes an argument of array of routes.

However I can't use functions because the serilization from server to client don't support functions.

How do people typically design this? I guess the routes need to be defined somewhere else so they aren't rendered as server components.

Or should my navbar be a server component, from my understanding it shouldn't be..

graceful ermine
#

Depends on what you want to do with your navbar.
You can make your navbar a server component, and its children client components, if they need to use hooks or events.

thick turret
#

I guess I need to find an example project using the new app folder

#

Navbar to mostly just go to pages on the website

graceful ermine
#

You can do that in a server component

#

However, for example if you want to highlight which page in your navbar is currently active, you'd need to make the nav items client components.

azure gorge
thick turret
#

I guess if I wanted to use a typescript class in that nav file

#

It'd have to be defined as use client ad well

graceful ermine
#

No, why?

thick turret
#

I defined the typescript class objects in an array in the layout.ts class

#

Then it seems doing that allows the class component to jot have access to functions