Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jsx): export FC #1420

Merged
merged 2 commits into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions deno_dist/jsx/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { html } from '../helper/html/index.ts'
import { Hono } from '../hono.ts'
import type { FC } from './index.ts'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { jsx, memo, Fragment } from './index.ts'

Expand Down Expand Up @@ -271,6 +272,32 @@ describe('render to string', () => {
})
})

describe('FC', () => {
it('Should define the type correctly', () => {
const Layout: FC<{ title: string }> = (props) => {
return (
<html>
<head>
<title>{props.title}</title>
</head>
<body>{props.children}</body>
</html>
)
}

const Top = (
<Layout title='Home page'>
<h1>Hono</h1>
<p>Hono is great</p>
</Layout>
)

expect(Top.toString()).toBe(
'<html><head><title>Home page</title></head><body><h1>Hono</h1><p>Hono is great</p></body></html>'
)
})
})

describe('style attribute', () => {
it('should convert the object to strings', () => {
const template = (
Expand Down
4 changes: 2 additions & 2 deletions deno_dist/jsx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ const jsxFn = (
}
}

type FC<T = Props> = (props: T) => HtmlEscapedString
export type FC<T = Props> = (props: T & { children?: Child }) => HtmlEscapedString

const shallowEqual = (a: Props, b: Props): boolean => {
if (a === b) {
Expand Down Expand Up @@ -226,7 +226,7 @@ export const memo = <T>(
): FC<T> => {
let computed = undefined
let prevProps: T | undefined = undefined
return ((props: T): HtmlEscapedString => {
return ((props: T & { children?: Child }): HtmlEscapedString => {
if (prevProps && !propsAreEqual(prevProps, props)) {
computed = undefined
}
Expand Down
27 changes: 27 additions & 0 deletions src/jsx/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { html } from '../helper/html'
import { Hono } from '../hono'
import type { FC } from './index'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { jsx, memo, Fragment } from './index'

Expand Down Expand Up @@ -271,6 +272,32 @@ describe('render to string', () => {
})
})

describe('FC', () => {
it('Should define the type correctly', () => {
const Layout: FC<{ title: string }> = (props) => {
return (
<html>
<head>
<title>{props.title}</title>
</head>
<body>{props.children}</body>
</html>
)
}

const Top = (
<Layout title='Home page'>
<h1>Hono</h1>
<p>Hono is great</p>
</Layout>
)

expect(Top.toString()).toBe(
'<html><head><title>Home page</title></head><body><h1>Hono</h1><p>Hono is great</p></body></html>'
)
})
})

describe('style attribute', () => {
it('should convert the object to strings', () => {
const template = (
Expand Down
4 changes: 2 additions & 2 deletions src/jsx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ const jsxFn = (
}
}

type FC<T = Props> = (props: T) => HtmlEscapedString
export type FC<T = Props> = (props: T & { children?: Child }) => HtmlEscapedString

const shallowEqual = (a: Props, b: Props): boolean => {
if (a === b) {
Expand Down Expand Up @@ -226,7 +226,7 @@ export const memo = <T>(
): FC<T> => {
let computed = undefined
let prevProps: T | undefined = undefined
return ((props: T): HtmlEscapedString => {
return ((props: T & { children?: Child }): HtmlEscapedString => {
if (prevProps && !propsAreEqual(prevProps, props)) {
computed = undefined
}
Expand Down