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

Include ReactNode in render method result #1062

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions examples/basic-no-jsx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Found Basic Example
13 changes: 13 additions & 0 deletions examples/basic-no-jsx/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Found Basic No JSX Example</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/index.ts"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions examples/basic-no-jsx/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "basic",
"version": "0.1.0",
"private": true,
"dependencies": {
"found": "*",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"scripts": {
"start": "vite"
},
"devDependencies": {
"@types/react-dom": "^18.2.18",
"@vitejs/plugin-react": "^2.0.1",
"typescript": "^5.3.3",
"vite": "^3.0.7",
"yalc": "^1.0.0-pre.53"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
7 changes: 7 additions & 0 deletions examples/basic-no-jsx/src/Bar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createElement } from 'react';

function Bar({ data }: { data: string }) {
return createElement('div', null, data);
}

export default Bar;
79 changes: 79 additions & 0 deletions examples/basic-no-jsx/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { Link, LinkProps, Redirect, createBrowserRouter } from 'found';
import { ReactElement, StrictMode, createElement } from 'react';
import { createRoot } from 'react-dom/client';

function LinkItem(props: LinkProps) {
return createElement(
'li',
null,
createElement(Link, { ...props, activeStyle: { fontWeight: 'bold' } }),
);
}

function App({ children }: { children: ReactElement[] }) {
return createElement(
'div',
null,
createElement(
'ul',
null,
createElement(LinkItem, { to: '/' }, 'Main'),
createElement(
'ul',
null,
createElement(LinkItem, { to: '/foo' }, 'Foo'),
createElement(LinkItem, { to: '/bar' }, 'Bar (async)'),
createElement(LinkItem, { to: '/baz' }, 'Baz (redirects to Foo)'),
createElement(LinkItem, { to: '/qux' }, 'Qux (missing)'),
),
),
children,
);
}

const BrowserRouter = createBrowserRouter({
routeConfig: [
{
path: '/',
Component: App,
children: [
{
Component: () => createElement('div', null, 'Main'),
},
{
path: 'foo',
Component: () => createElement('div', null, 'Foo'),
},
{
path: 'bar',
getComponent: () => import('./Bar').then((m) => m.default),
getData: () =>
new Promise((resolve) => {
setTimeout(resolve, 1000, 'Bar');
}),
render: ({ Component, props }) =>
Component && props
? createElement(Component, props)
: createElement(
'div',
null,
createElement('small', null, 'Loading&hellip;'),
),
},
new Redirect({
from: 'baz',
to: '/foo',
}),
Comment on lines +63 to +66
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what didn't compile despite it being valid.

],
},
],

renderError: ({ error }) =>
createElement('div', null, error.status === 404 ? 'Not found' : 'Error'),
});

const root = createRoot(document.getElementById('root'));

root.render(
createElement(StrictMode, null, createElement(BrowserRouter, null)),
);
7 changes: 7 additions & 0 deletions examples/basic-no-jsx/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"include": ["./src"],
"compilerOptions": {
"lib": ["DOM"]
}
}
7 changes: 7 additions & 0 deletions examples/basic-no-jsx/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()]
})
Loading