Skip to content

Commit

Permalink
chore: Improved readme. Simplified main and App code.
Browse files Browse the repository at this point in the history
  • Loading branch information
yusinto committed Sep 8, 2024
1 parent 973be68 commit 1eeb73d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
# React + TypeScript + Vite
# LaunchDarkly React Typescript application

This is an example Launchdarkly React Typescript application scaffolded with create-vite. To run:

1. Enter your clientSideID in [main.tsx](https://github.com/launchdarkly-labs/react-ts/blob/main/src/main.tsx#L8).

2. Replace yourFlagkey in [App.tsx](https://github.com/launchdarkly-labs/react-ts/blob/main/src/App.tsx#L5) with your flag key.

3. `npm run dev`.

Below is the original readme generated by create-vite.

## React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Expand Down
39 changes: 10 additions & 29 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,15 @@
import { useState } from 'react'
import { useFlags } from 'launchdarkly-react-client-sdk'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'
import { useFlags } from 'launchdarkly-react-client-sdk';

function App() {
const [count, setCount] = useState(0)
const { booleanFlag1 } = useFlags()
// README: replace yourFlagKey with your own flag key
const { yourFlagKey: flagKey } = useFlags();

return (
<>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React</h1>
<p>{booleanFlag1 ? <b>Flag on</b> : <b>Flag off</b>}</p>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>count is {count}</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs">Click on the Vite and React logos to learn more</p>
</>
)
}
<div style={{ backgroundColor: flagKey ? 'green' : 'red' }}>
The feature flag evaluates to <b>{flagKey ? 'true' : 'false'}</b>
</div>
);
}

export default App

export default App;
3 changes: 2 additions & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { LDProvider } from 'launchdarkly-react-client-sdk'
import App from './App.tsx'
import './index.css'

const clientSideID = import.meta.env.VITE_CLIENT_SIDE_ID ?? ''
// // README: set your clientSideId
const clientSideID = import.meta.env.VITE_CLIENT_SIDE_ID ?? 'your-client-side-id'

createRoot(document.getElementById('root')!).render(
<StrictMode>
Expand Down

0 comments on commit 1eeb73d

Please sign in to comment.