1.0.1 • Published 2 years ago

@devlu/nextenv v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Next.js Runtime Environment Variables

Getting Started

Install

npm i @devlu/nextenv

Add the following to your app/layout.tsx file:

// app/layout.tsx
import { EnvProvider } from '@devlu/nextenv'

export const dynamic = 'force-dynamic' // <-- this is required

export default function Layout({ children }) {
  return (
    <html lang="en">
      <body>
        <EnvProvider>
          {children}
        </EnvProvider>
      </body>
    </html>
  )
}

Usage

For Server-Side

import { useEnv } from '@devlu/nextenv'

export default function Home() {
  const env = useEnv()
  return (
    <div>
      <h1>{env.MY_ENV_VAR}</h1>
    </div>
  )
}

For Client-Side

Only variables that start with ENV_PUBLIC_ are available on the client side.

'use client'

import { useClientEnv } from '@devlu/nextenv'

export default function Home() {
  const env = useClientEnv()
  return (
    <div>
      <h1>{env.ENV_PUBLIC_MY_ENV_VAR}</h1>
    </div>
  )
}
1.0.1

2 years ago

1.0.0

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago