Skip to content

Instantly share code, notes, and snippets.

View juriadams's full-sized avatar

Juri Adams juriadams

View GitHub Profile
@juriadams
juriadams / render.tsx
Created July 17, 2023 10:51
Render React Component to HTML String with Type-Safe Prop Validation
import { renderToStaticMarkup } from 'react-dom/server';
import { type ComponentType } from 'react';
/**
* Converts a specified React component to its HTML string representation.
* @param Component A React component to be rendered, for instance, `AccountSignInEmail`.
* @param props An object containing the props to be passed to the Component. Type safety is enforced.
* @returns The HTML string representation of the rendered component.
*/
export const render = <P extends object>(Component: ComponentType<P>, props: P): string =>
@juriadams
juriadams / dump.ts
Last active August 10, 2023 17:01
Cloudflare Snippets
interface Env {
DATABASE: D1Database;
}
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const tables = await env.DATABASE.prepare(
"SELECT tbl_name, sql FROM sqlite_master WHERE type='table' AND tbl_name NOT LIKE '_cf_KV' AND tbl_name NOT LIKE 'sqlite_stat1';"
)
.all()