{"bugs":{"url":"https://github.com/phryneas/rehackt/issues"},"dist":{"shasum":"715861bf228a7306243ee900a077182ebb463bd8","tarball":"https://registry.npmjs.org/rehackt/-/rehackt-0.0.0-pr.10.0.tgz","fileCount":6,"integrity":"sha512-RG3QtgONbhnW6BIoAX9ZOrkNIfhblgFUjM+UDyXRsnT3eLHZslWUAHhikIkLe41P8hWf9vZBi3yjfb12N+JVfw==","signatures":[{"sig":"MEYCIQDdFbGCso3Z0ABzMceeSZgwIOJMg1Eh1ueGam9P8hy8WwIhAMkebL2IBvu4FMrkWLDSfXmJoVbA1PMx9EjVaZkAd/Zp","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/rehackt@0.0.0-pr.10.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":10124},"main":"index.js","name":"rehackt","types":"./index.d.ts","author":{"name":"Lenz Weber-Tronic"},"readme":"# Rehackt\r\n\r\n> This package is fairly advanced and is only intended for library developers that want to maintain high interop with Next.js server actions.\r\n\r\nRehackt invisibly wraps `react` so that you're able to use shared imports with `react` in server-side Next.js code without throwing an error to your users.\r\n\r\n## Explainer\r\n\r\nAssume you have the following code in a Next.js codebase:\r\n\r\n```tsx\r\n\"use client\"\r\n\r\nimport { useFormState } from \"react-dom\"\r\nimport someAction from \"./action\";\r\n\r\nexport const ClientComp = () => {\r\n  const [data, action] = useFormState(someAction, \"Hello client\");\r\n\r\n  return <form action={action}>\r\n    <p>{data}</p>\r\n    <button type={\"submit\"}>Update data</button>\r\n  </form>\r\n}\r\n```\r\n\r\n```tsx\r\n\"use server\"\r\n// action.ts\r\n\r\nimport {data} from \"./shared-code\";\r\n\r\nexport default async function someAction() {\r\n  return \"Hello \" + data.name;\r\n}\r\n```\r\n\r\n```tsx\r\n// shared-code.ts\r\nimport {useState} from \"react\";\r\n\r\nexport const data = {\r\n  useForm: <T>(val: T) => {\r\n      useState(val)\r\n  },\r\n  name: \"server\"\r\n}\r\n```\r\n\r\nWhile you're not intending to use `data.useForm` in your `action.ts` server-only file, you'll still receive the following error from Next.js' build process when trying to use this code:\r\n\r\n```shell\r\n./src/app/shared-code.ts\r\nReactServerComponentsError:\r\n\r\nYou're importing a component that needs useState. It only works in a Client Component but none of its parents are marked with \"use client\", so they're Server Components by default.\r\nLearn more: https://nextjs.org/docs/getting-started/react-essentials\r\n\r\n   ╭─[/src/app/shared-code.ts:1:1]\r\n 1 │ import {useState} from \"react\";\r\n   ·         ────────\r\n 2 │ \r\n 3 │ export const data = {\r\n 3 │   useForm: <T>(val: T) => {\r\n   ╰────\r\n\r\nMaybe one of these should be marked as a client entry with \"use client\":\r\n./src/app/shared-code.ts\r\n./src/app/action.ts\r\n```\r\n\r\nThis is because Next.js statically analyzes usage of `useState` to ensure it's not being utilized in server-only code.\r\n\r\nBy replacing the import from `react` to `rehackt`:\r\n\r\n```tsx\r\n// shared-code.ts\r\nimport {useState} from \"rehackt\";\r\n\r\nexport const data = {\r\n  useForm: <T>(val: T) => {\r\n      useState(val)\r\n  },\r\n  name: \"server\"\r\n}\r\n```\r\n\r\nYou'll no longer see this error.\r\n\r\n> Keep in mind, this does not enable usage of `useState` in server-only code, this just removes the error described above.\r\n\r\n## Further Reading\r\n\r\nThe following is a list of reading resources that pertain to this package:\r\n\r\n- [My take on the current React & Server Components controversy - Lenz Weber-Tronic](https://phryneas.de/react-server-components-controversy)\r\n\r\n- [apollographql/apollo-client#10974](https://github.com/apollographql/apollo-client/issues/10974)\r\n\r\n- [TanStack/form#480](https://github.com/TanStack/form/issues/480#issuecomment-1793576645)\r\n","exports":{".":{"types":"./index.d.ts","default":"./index.js","react-server":"./rsc.js"},"./package.json":"./package.json"},"gitHead":"a83bf86c89a375b9c5d354c4f6a14055526fba82","license":"MIT","_npmUser":{"name":"phryneas","email":"mail@lenzw.de"},"homepage":"https://github.com/phryneas/rehackt","prettier":{"printWidth":120},"repository":{"url":"git+https://github.com/phryneas/rehackt.git","type":"git"},"_npmVersion":"10.5.0","description":"A wrapper around React that will hide hooks from the React Server Component compiler","directories":{},"maintainers":[{"name":"phryneas","email":"mail@lenzw.de"}],"_nodeVersion":"18.20.2","_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"react":"^19.0.0-canary-33a32441e9-20240418","@types/node":"^20.5.7"},"peerDependencies":{"react":"*","@types/react":"*"},"peerDependenciesMeta":{"react":{"optional":true},"@types/react":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/rehackt_0.0.0-pr.10.0_1713779385680_0.9706141598619316","host":"s3://npm-registry-packages"},"_id":"rehackt@0.0.0-pr.10.0","version":"0.0.0-pr.10.0"}