Skip to content

Commit

Permalink
feat(AP-1778): add support for providing config via env file
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Strom committed Sep 7, 2022
1 parent b03374c commit ace7ca6
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Copy lines below into a file named ".env.local"

NEXT_PUBLIC_EVOLV_CONFIG='{"environment":"df7109b048"}'
REACT_APP_EVOLV_CONFIG='{"environment":"df7109b048"}'
9 changes: 9 additions & 0 deletions examples/nextjs/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare global {
namespace NodeJS {
interface ProcessEnv {
NEXT_PUBLIC_EVOLV_CONFIG: string;
}
}
}

export {};
5 changes: 1 addition & 4 deletions examples/nextjs/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import Button from './button';
import Heading from './heading';


const options: EvolvClientOptions = {
environment: 'df7109b048',
endpoint: 'https://participants-newdev.evolvdev.com/'
};
const options: EvolvClientOptions = JSON.parse(process.env.NEXT_PUBLIC_EVOLV_CONFIG ?? '{}');

const Home: FC<EvolvServerSideProps & UserIdProps> = (props) => {
return (
Expand Down
1 change: 1 addition & 0 deletions examples/nextjs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"jsx": "preserve"
},
"include": [
"env.d.ts",
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
Expand Down
9 changes: 9 additions & 0 deletions examples/react/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare global {
namespace NodeJS {
interface ProcessEnv {
REACT_APP_EVOLV_CONFIG: string;
}
}
}

export {};
16 changes: 7 additions & 9 deletions examples/react/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import { EvolvClientOptions } from '@evolv/client';
import { EvolvProvider } from '@evolv/react';
import { EvolvClientOptions, EvolvProvider } from '@evolv/react';
import { StrictMode } from 'react';
import ReactDOM from 'react-dom';

import App from './App';
import { getUid } from './utils/uid';


const rootElement = document.getElementById('root');

const options: EvolvClientOptions = {
environment: 'df7109b048',
endpoint: 'https://participants-newdev.evolvdev.com/'
};
const options: EvolvClientOptions = JSON.parse(process.env.REACT_APP_EVOLV_CONFIG ?? '{}');

const remoteContext = {
customizeButton: false
} as any;

};

const uid = getUid();

ReactDOM.render(
<StrictMode>
<EvolvProvider options={options} uid="12345678908" remoteContext={remoteContext}>
<EvolvProvider options={options} uid={uid} remoteContext={remoteContext}>
<App />
</EvolvProvider>
</StrictMode>
Expand Down
4 changes: 4 additions & 0 deletions examples/react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
"dom",
"es2015"
],
"types": [
"./env.d.ts",
"node"
],
"jsx": "react-jsx"
},
"include": [
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/evolv.provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ interface BaseProps {
options: EvolvClientOptions;
uid: string;
hydratedState?: Record<string, any>;
remoteContext?: RemoteContext;
localContext?: LocalContext;
remoteContext?: Partial<RemoteContext>;
localContext?: Partial<LocalContext>;
}

export const EvolvProvider: FC<BaseProps> =
Expand Down

0 comments on commit ace7ca6

Please sign in to comment.