Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lorissigrist/rsc-env
A tiny package that uses export conditions do differentiate between server-component and non-server-component environments
https://github.com/lorissigrist/rsc-env
app-router app-router-nextjs nextjs14 react-server-components rsc
Last synced: 11 days ago
JSON representation
A tiny package that uses export conditions do differentiate between server-component and non-server-component environments
- Host: GitHub
- URL: https://github.com/lorissigrist/rsc-env
- Owner: LorisSigrist
- License: mit
- Created: 2024-04-18T08:17:52.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-04-22T14:48:02.000Z (7 months ago)
- Last Synced: 2024-10-12T08:47:11.991Z (26 days ago)
- Topics: app-router, app-router-nextjs, nextjs14, react-server-components, rsc
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# RSC-ENV
Inspired by the brilliant [`esm-env`](https://github.com/benmccann/esm-env?tab=readme-ov-file)
Uses export conditions to return if the current environment is `react-server` or not. Bundlers can statically determine the environment at build time & remove dead code.
This is useful for writing utility functions that may be called by either server or client components.
## Example
```bash
npm install rsc-env
``````ts
// utils/shared.ts
import { rsc } from "rsc-env";// This code will be treeshaken from client-component builds
if(rsc) console.log("I'm running in a server component")
```## License
[MIT](./LICENSE.md)