Skip to content

Instantly share code, notes, and snippets.

@asaschachar
Last active May 30, 2019 23:31
Show Gist options
  • Save asaschachar/c19a9ece803c866e63065e6200286be2 to your computer and use it in GitHub Desktop.
Save asaschachar/c19a9ece803c866e63065e6200286be2 to your computer and use it in GitHub Desktop.
react-feature-flags-blog
<OptimizelyFeature feature="hello_world">
{(isEnabled) => (
isEnabled
? (<p> You got the <strong>hello_world</strong> feature! </p>)
: (<p> You did not get the feature </p>)
)}
</OptimizelyFeature>
import React from 'react';
import { OptimizelyProvider, OptimizelyFeature } from '@optimizely/react-sdk'
import * as optimizelySDK from '@optimizely/js-web-sdk'
const optimizely = optimizelySDK.createInstance({
sdkKey: '<Your_SDK_Key>',
})
class App extends React.Component {
render() {
return (
<OptimizelyProvider
optimizely={optimizely}
userId={'user123'}
userAttributes={{
'customerId': 123,
'isVip': true,
}}>
<h1>Example Application</h1>
<div>
<OptimizelyFeature feature="hello_world">
{(isEnabled) => (
isEnabled
? (<p> You got the <strong>hello_world</strong> feature! </p>)
: (<p> You did not get the feature </p>)
)}
</OptimizelyFeature>
</div>
</OptimizelyProvider>
)
}
}
export default App;
import React from 'react';
import { OptimizelyProvider } from '@optimizely/react-sdk'
import * as optimizelySDK from '@optimizely/js-web-sdk'
const optimizely = optimizelySDK.createInstance({
sdkKey: '<Your_SDK_Key>',
})
class App extends React.Component {
render() {
return (
<OptimizelyProvider
optimizely={optimizely}
userId={'user123'}
userAttributes={{
'customerId': 123,
'isVip': true,
}}>
<h1>Example Application</h1>
<div>
No features here yet...
</div>
</OptimizelyProvider>
)
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment