Skip to content

A tiny package that uses export conditions do differentiate between server-component and non-server-component environments

License

Notifications You must be signed in to change notification settings

LorisSigrist/rsc-env

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RSC-ENV

Inspired by the brilliant esm-env

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

npm install rsc-env
// 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

About

A tiny package that uses export conditions do differentiate between server-component and non-server-component environments

Topics

Resources

License

Stars

Watchers

Forks