
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
@sodefa/next-server-context
Advanced tools
The missing server context for Next.js App Directory.
The missing server context for Next.js App Directory.
pnpm add @sodefa/next-server-context
/app/[myParam]/page.tsx
import { pageContext } from '@sodefa/next-server-context'
import { NestedServerComponent } from './NestedServerComponent'
export default pageContext.Wrapper(({ params, searchParams }) => {
return (
<>
<h1>MyPage</h1>
<NestedServerComponent />
</>
)
})
/app/[myParam]/NestedServerComponent.tsx
import { pageContext } from '@sodefa/next-server-context'
export const NestedServerComponent = () => {
const { params, searchParams } = pageContext.getOrThrow()
return <div>NestedServerComponent: {params.myParam}</div>
}
/myContext.ts
import { createServerContext } from '@sodefa/next-server-context'
const myContext = createServerContext<{
myValue: string
}>()
/ParentComp.tsx
import { myContext } from './myContext'
export const ParentComp = () => {
myContext.set({ myValue: 'hi there' })
return <ChildComp />
}
/ChildComp.tsx
import { myContext } from './myContext'
export const ChildComp = () => {
const { myValue } = myContext.getOrThrow()
return <div>ChildComp: {myValue}</div>
}
/app/zod/[singleParam]/[...deepParams]/myContext.ts
import { createServerContextWithZod } from '@sodefa/next-server-context'
import { z } from 'zod'
export const myContext = createServerContextWithZod(
z.object({
params: z.object({
singleParam: z.string(),
deepParams: z.array(z.string()),
}),
searchParams: z
.object({
p1: z.string().optional(),
p2: z.array(z.string()).optional(),
})
.catchall(z.union([z.string(), z.array(z.string())])), // Allow additional search params (optional)
})
)
/app/zod/[singleParam]/[...deepParams]/page.tsx
import { NestedServerComponent } from './NestedServerComponent'
import { myContext } from './myContext'
export default myContext.Wrapper(() => {
return (
<>
<h1>Page with a lot of Params</h1>
<NestedServerComponent />
</>
)
})
/app/zod/[singleParam]/[...deepParams]/NestedServerComponent.tsx
import { myContext } from './myContext'
export const NestedServerComponent = () => {
const { params, searchParams } = myContext.getOrThrow()
return (
<pre className="p-2 border rounded flex flex-col gap-4 font-mono text-xs ">
{JSON.stringify({ params, searchParams }, null, 2)}
</pre>
)
}
FAQs
The missing server context for Next.js App Directory.
The npm package @sodefa/next-server-context receives a total of 8 weekly downloads. As such, @sodefa/next-server-context popularity was classified as not popular.
We found that @sodefa/next-server-context demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.