fix: lint typescript source

This commit is contained in:
Valerio Ageno
2024-06-16 10:44:33 +02:00
parent b3ef9f0ee6
commit a72656cb4b
6 changed files with 20 additions and 37 deletions
+4 -2
View File
@@ -2,12 +2,14 @@ import React from 'react'
import ReactDOM from 'react-dom/client'
import { RouterProvider, createRouter } from '../router'
export function hydrate(routeTree: any) {
type RouteTree = any
export function hydrate(routeTree: RouteTree): void {
// Create a new router instance
const router = createRouter({ routeTree })
// Render the app
const rootElement = document.getElementById('__tuono')!
const rootElement = document.getElementById('__tuono')
ReactDOM.hydrateRoot(
rootElement,
@@ -1,6 +1,7 @@
import * as React from 'react'
import type { Router } from '../router'
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const routerContext = React.createContext<Router>(null!)
const TUONO_CONTEXT = '__TUONO_CONTEXT__'
@@ -9,16 +9,22 @@ interface UseServerSidePropsReturn {
isLoading: boolean
}
declare global {
interface Window {
__TUONO_SSR_PROPS__: any
}
}
/*
* Use the props provided by the SSR and dehydrate the
* props for client side usage.
*
* In case is a client fetch the remote data API
*/
export function useServerSideProps(
export function useServerSideProps<T>(
route: Route,
// User defined props
serverSideProps: any,
serverSideProps: T,
): UseServerSidePropsReturn {
const isFirstRendering = useRef<boolean>(true)
const location = useRouterStore((st) => st.location)
-6
View File
@@ -1,9 +1,3 @@
declare global {
interface Window {
__TUONO_SSR__PROPS__: any
}
}
export { RouterProvider } from './components/RouterProvider'
export { default as Link } from './components/Link'
export { createRouter } from './router'
+4 -26
View File
@@ -40,7 +40,6 @@ export class Route {
const isRoot = !this.options?.path && !this.options?.id
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
this.parentRoute = this.options?.getParentRoute?.()
if (isRoot) {
@@ -75,11 +74,10 @@ export class Route {
const fullPath =
id === rootRouteId ? '/' : joinPaths([this.parentRoute.fullPath, path])
this.path = path as TPath
this.id = id as TId
// this.customId = customId as TCustomId
this.fullPath = fullPath as TFullPath
this.to = fullPath as TrimPathRight<TFullPath>
this.path = path
this.id = id
this.fullPath = fullPath
this.to = fullPath
}
addChildren(routes: Route[]): Route {
@@ -92,28 +90,8 @@ export class Route {
this.isRoot = options.isRoot || !options.getParentRoute
return this
}
useRouteContext = () => {}
useParams = () => {}
}
export function createRootRoute(options?: RouteOptions): Route {
return new Route({ ...options, isRoot: true })
}
export function getRouteApi(id: string): RouteApi {
return new RouteApi(id)
}
class RouteApi {
id: string
constructor(id: string) {
this.id = id
}
useParams = () => {}
useRouteContext = () => {}
}
+3 -1
View File
@@ -4,7 +4,9 @@ import { renderToString, renderToStaticMarkup } from 'react-dom/server'
import { RouterProvider } from '../router'
import { createRouter } from '../router'
export function serverSideRendering(routeTree: any) {
type RouteTree = any
export function serverSideRendering(routeTree: RouteTree) {
return function render(payload: string | undefined): string {
const props = payload ? JSON.parse(payload) : {}