File tree Expand file tree Collapse file tree 1 file changed +25
-5
lines changed Expand file tree Collapse file tree 1 file changed +25
-5
lines changed Original file line number Diff line number Diff line change
1
+ import { useEffect , useState } from 'react'
2
+
1
3
/**
2
4
* https://nextjs.org/docs/basic-features/environment-variables
3
5
*/
4
6
function EnvTest ( ) {
7
+ const [ showEnv , setShowEnv ] = useState ( false )
8
+ useEffect ( ( ) => setShowEnv ( true ) , [ ] )
5
9
return (
6
10
< div >
7
11
< h1 > Environment Variables</ h1 >
8
12
< a href = "https://nextjs.org/docs/basic-features/environment-variables" > Read Docs</ a >
9
- < p > By default environment variables are only available in the Node.js environment, meaning they won't be exposed to the browser.</ p >
10
13
< p >
11
- < code > NEXT_PUBLIC_</ code > environment variables are available in the browser, and can be used to configure the application.
14
+ By default environment variables are only available in the Node.js environment, meaning they won't be
15
+ exposed to the browser.
16
+ </ p >
17
+ < p >
18
+ < code > NEXT_PUBLIC_</ code > environment variables are available in the browser, and can be used to configure the
19
+ application.
12
20
</ p >
13
- < p > ✅ Public Environment token found: < code > { process . env . NEXT_PUBLIC_GREETINGS || 'NOT FOUND (something went wrong)' } </ code > </ p >
14
- < p > ❌ Private Environment token should not be found: < code > { process . env . TEST_ENV_VAR || 'Everything worked' } </ code > </ p >
21
+ { showEnv ? (
22
+ < >
23
+ < p >
24
+ ✅ Public Environment token found:{ ' ' }
25
+ < code > { process . env . NEXT_PUBLIC_GREETINGS || 'NOT FOUND (something went wrong)' } </ code >
26
+ </ p >
27
+ < p >
28
+ ❌ Private Environment token should not be found:{ ' ' }
29
+ < code > { process . env . TEST_ENV_VAR || 'Everything worked' } </ code >
30
+ </ p >
31
+ </ >
32
+ ) : (
33
+ 'We only want to test client-side env vars'
34
+ ) }
15
35
</ div >
16
36
)
17
37
}
18
38
19
- export default EnvTest
39
+ export default EnvTest
You can’t perform that action at this time.
0 commit comments