Nagranie.z.ekranu.2023-03-13.o.23.10.10.mov
useNode
React server hook
This is a hook working with React Server Component (RSC) and Next.js with App Router.
npm install use-node
or
yarn add use-node
or
pnpm add use-node
import { useNode } from "use-node";
import { ClientComponent } from "./ClientComponent";
export default async function App() {
const process = await useNode("node:process");
console.log("env", process.env.NODE_ENV); // server log
// pass this to the Client Component
return <ClientComponent data={process.env.NODE_ENV} />;
}
const data = await useNode(module: Modules)
type Modules =
| "node:async_hooks"
| "node:buffer"
| "node:child_process"
| "node:cluster"
| "node:console"
| "node:constants"
| "node:dgram"
| "node:diagnostics_channel"
| "node:dns"
| "node:dns/promises"
| "node:fs"
| "node:fs/promises"
| "node:http"
| "node:http2"
| "node:https"
| "node:inspector"
| "node:net"
| "node:os"
| "node:path"
| "node:perf_hooks"
| "node:process"
| "node:querystring"
| "node:readline"
| "node:repl"
| "node:stream/promises"
| "node:stream/web"
| "node:string_decoder"
| "node:timers"
| "node:timers/promises"
| "node:tls"
| "node:trace_events"
| "node:tty"
| "node:url"
| "node:util"
| "node:v8"
| "node:vm"
| "node:wasi"
| "node:worker_threads"
| "node:zlib";
https://github.com/irekrog/rsc-server-data-example/blob/master/src/app/use-node/page.tsx