
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
State for React Server Components (RSC) on Next.js
N: Next.js
R: React Server Components
State
✨ Next.js 13 support, for RSC
npm i nrstate
npm i nrstate-client
You can play with the example code here.
https://github.com/vteacher-online/nrstate-demo
Implement persistence, read or write by observing all state changes across your page, without impairing code-splitting.
A PageState represents a state of Page-component.
Client-component
PageState can be read
and write
from any Client-component.
Server-component
PageState can be read
from any Server-component.
ex.
export const pathDemo = '/demo';
export type PageStateDemo = {
a: string;
d: string;
};
export const initialPageStateDemo = { a: '', d: 'asc' } as PageStateDemo;
Components that use nrstate need <PageStateProvider>
to appear somewhere in the parent tree. A good place to put this is in your root component.
Make the "page" Server-component.
( Do not write "use client" )
export default function Page() {
return (
<PageStateProvider
current={currentPageState<PageStateDemo>(
initialPageStateDemo,
pathDemo,
)}
>
<></>
</PageStateProvider>
);
}
'use client';
export default function ClientComponent() {
const [pageState, setPageState] = usePageState<PageStateDemo>();
const { a, d } = pageState;
return (
<>
a={a}, d={d}
</>
);
}
export default async function ServerComponent() {
const pageState = getPageState<PageStateDemo>(initialPageStateDemo, pathDemo);
const { a, d } = pageState;
return (
<>
a={a}, d={d}
</>
);
}
Client-component can use this. PageState updates will result in a re-render of all components subscribed to that Page-component.
'use client';
export default function ClientComponentInput() {
const [pageState, setPageState] = usePageState<PageStateDemo>();
const { a } = pageState;
return (
<input type="text" onChange={(e) => {
setPageState({
...pageState,
a: e.target.value,
}, pathDemo);
}}
/>
);
}
useState
and usePageState
can be used together.
You can play with the example code here.
https://github.com/vteacher-online/nrstate-demo
Then, http://localhost:3000/
FAQs
State for React Server Components on Next.js
The npm package nrstate receives a total of 107 weekly downloads. As such, nrstate popularity was classified as not popular.
We found that nrstate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.