Skip to content

Commit f61d5dd

Browse files
committed
one less react example
1 parent 8f7072f commit f61d5dd

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

pages/docs/manual/latest/module-functions.mdx

+8-8
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,23 @@ export {
9999

100100
## Sharing a type with an external binding
101101
This becomes incredibly useful when you need to have types that are unique to a project but shared across multiple components.
102-
Let's say you want to create a library with a `useEnv` hook to load in environment variables found in `import.meta.env`.
102+
Let's say you want to create a library with a `getEnv` function to load in environment variables found in `import.meta.env`.
103103
```res
104104
@val external env: 'a = "import.meta.env"
105105
106-
let useEnv = () => {
106+
let getEnv = () => {
107107
env
108108
}
109109
```
110-
It's not possible to define types for this that will work for every project, so we just set it as 'a and the consumer of our library can define the return type when they use the hook.
110+
It's not possible to define types for this that will work for every project, so we just set it as 'a and the consumer of our library can define the return type when they use the function.
111111
```res
112112
type t = {"LOG_LEVEL": string}
113113
114-
let values: t = useEnv()
114+
let values: t = getEnv()
115115
```
116116
This isn't great and it doesn't take advantage of ReScript's type system and ability to use types without type definitions, and it can't be easily shared across our application.
117117

118-
We can instead create a module function that can return a module that has contains a `useEnv` hook that has a typed response.
118+
We can instead create a module function that can return a module that has contains a `getEnv` hook that has a typed response.
119119
```res
120120
module MakeEnv = (
121121
E: {
@@ -124,7 +124,7 @@ module MakeEnv = (
124124
) => {
125125
@val external env: E.t = "import.meta.env"
126126
127-
let useEnv = () => {
127+
let getEnv = () => {
128128
env
129129
}
130130
}
@@ -138,11 +138,11 @@ module Env = MakeEnv({
138138
type t = {"LOG_LEVEL": string}
139139
})
140140
141-
let values = Env.useEnv()
141+
let values = Env.getEnv()
142142
```
143143
```js
144144
var Env = {
145-
useEnv: useEnv
145+
getEnv: getEnv
146146
};
147147

148148
var values = import.meta.env;

0 commit comments

Comments
 (0)