-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
<!DOCTYPE html> | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta name="theme-color" content="#000000" /> | ||
<meta name="description" content="Flagged Example website made with CRA" /> | ||
<title>Flagged Example</title> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id="root"></div> | ||
</body> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta name="theme-color" content="#000000" /> | ||
<meta name="description" content="Flagged Example website made with CRA" /> | ||
<title>Flagged Example</title> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id="root"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,65 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { FlagsProvider, withFeature, Feature, useFeature } from 'flagged'; | ||
import React from "react"; | ||
import ReactDOM from "react-dom"; | ||
import { FlagsProvider, withFeature, Feature, useFeature } from "flagged"; | ||
|
||
function VersionComponent({ version }) { | ||
return <h1>You are currently in {version}.</h1>; | ||
return <h1>You are currently in {version}.</h1>; | ||
} | ||
|
||
// Custom Hook | ||
function V1Component() { | ||
const hasV1 = useFeature('v1'); | ||
if (!hasV1) return null; | ||
return <VersionComponent version="v1" />; | ||
const hasV1 = useFeature("v1"); | ||
if (!hasV1) return null; | ||
return <VersionComponent version="v1" />; | ||
} | ||
|
||
// High Order Component | ||
const V2Component = withFeature('v2')(function V2Component() { | ||
return <VersionComponent version="v2" />; | ||
const V2Component = withFeature("v2")(function V2Component() { | ||
return <VersionComponent version="v2" />; | ||
}); | ||
|
||
function V3Component() { | ||
return <VersionComponent version="v3" />; | ||
return <VersionComponent version="v3" />; | ||
} | ||
|
||
function V4Component() { | ||
return <VersionComponent version="v4" />; | ||
return <VersionComponent version="v4" />; | ||
} | ||
|
||
function App() { | ||
const [version, setVersion] = React.useState(1); | ||
const [version, setVersion] = React.useState(1); | ||
|
||
return ( | ||
<FlagsProvider | ||
features={{ | ||
v1: version === 1, | ||
v2: version === 2, | ||
v3: version === 3, | ||
v4: version === 4, | ||
}} | ||
> | ||
<label> | ||
Version{' '} | ||
<input | ||
type="number" | ||
value={version} | ||
onChange={e => setVersion(Number(e.target.value))} | ||
/> | ||
</label> | ||
return ( | ||
<FlagsProvider | ||
features={{ | ||
v1: version === 1, | ||
v2: version === 2, | ||
v3: version === 3, | ||
v4: version === 4, | ||
}} | ||
> | ||
<label> | ||
Version{" "} | ||
<input | ||
type="number" | ||
value={version} | ||
onChange={(e) => setVersion(Number(e.target.value))} | ||
/> | ||
</label> | ||
|
||
<V1Component /> | ||
<V1Component /> | ||
|
||
<V2Component /> | ||
<V2Component /> | ||
|
||
{/* Render Prop */} | ||
<Feature name="v3" render={<V3Component />} /> | ||
{/* Render Prop */} | ||
<Feature name="v3" render={<V3Component />} /> | ||
|
||
{/* Function as Children */} | ||
<Feature name="v4"> | ||
{hasV4 => (hasV4 ? <V4Component /> : <h3>You are not in v4.</h3>)} | ||
</Feature> | ||
</FlagsProvider> | ||
); | ||
{/* Function as Children */} | ||
<Feature name="v4"> | ||
{(hasV4) => (hasV4 ? <V4Component /> : <h3>You are not in v4.</h3>)} | ||
</Feature> | ||
</FlagsProvider> | ||
); | ||
} | ||
|
||
ReactDOM.render(<App />, document.getElementById('root')); | ||
ReactDOM.render(<App />, document.getElementById("root")); |