Skip to content

Commit

Permalink
docs(getting-started): add section on using environment variables
Browse files Browse the repository at this point in the history
Add a new section to the "Getting started" guide, explaining how to access environment variables in the application using the `useAppEnvironmentVariables` hook from `@equinor/fusion-framework-react-app`.

Add  a code example demonstrating the usage of the hook.
  • Loading branch information
odinr committed May 23, 2024
1 parent 1a40851 commit f31189a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changeset/add-doc-environment-variables.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@equinor/fusion-framework-docs': patch
---

## @equinor/fusion-framework-docs

Updated the "Getting started" guide with a new section about using environment variables.
25 changes: 25 additions & 0 deletions vue-press/src/guide/app/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,31 @@ export default () => ({
:::
#### Environment variables
To access the environment variables in the application, use the hook `useAppEnvironmentVariables` from `@equinor/fusion-framework-react-app`.
```ts
import { useAppEnvironmentVariables } from '@equinor/fusion-framework-react-app';

type AppEnvironmentVariables = {
API_URL: string;
API_SCOPE: string;
}

const MyComponent = () => {
const env = useAppEnvironmentVariables<AppEnvironmentVariables>();
console.log(env); // { API_URL: 'https://foo.bar', API_SCOPE: 'c5161f15-9930-4cfc-b233-e9dfc5f8ad82/.default' }
}
```
> [!INFO]
> The `useAppEnvironmentVariables` hook consumes asyncronous data from the app service.
> In theory the value should always be available, since loaded during configuration.
>
> There will be a future module which manages application state, where during the configuration the
> desired environment variables can be picked.
## Creating Application
### Main
Expand Down

0 comments on commit f31189a

Please sign in to comment.