Skip to content

Commit 1cfe7c7

Browse files
LaunchDarklyReleaseBotkinyoklionLaunchDarklyReleaseBotyusinto
authored
prepare 3.0.5 release (#196)
* build(deps): Update to js-client-sdk 3.1.2 (#98) * chore: Adding a typescript example (#99) * chore: initial commit * fix: ignore example tests * build(deps): Update js-client-sdk to 3.1.3. (#100) --------- Co-authored-by: Ryan Lamb <[email protected]> Co-authored-by: LaunchDarklyReleaseBot <[email protected]> Co-authored-by: Yusinto Ngadiman <[email protected]>
1 parent 9bcd9ea commit 1cfe7c7

File tree

16 files changed

+306
-2
lines changed

16 files changed

+306
-2
lines changed

examples/typescript/.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
25+
public

examples/typescript/README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# LaunchDarkly SDK for React - Example typescript app
2+
3+
This is a CRA typescript app demonstrating `launchdarkly-react-client-sdk`.
4+
5+
## Running the typescript example
6+
7+
Follow these steps to run the app:
8+
9+
* Create a `.env.local` file and set your clientSideID there like so:
10+
11+
```shell
12+
REACT_APP_LD_CLIENT_SIDE_ID=xxx
13+
```
14+
15+
* Create a flag called `dev-test-flag` in your project. Make sure you
16+
make the flag available to the client-side SDK.
17+
18+
* You should now be able to start the app by doing:
19+
20+
```sh
21+
yarn && yarn start
22+
```
23+
24+
* Toggle the killswitch for `dev-test-flag` in the dashboard and the
25+
app should respond without a browser refresh.
26+
27+
# Getting Started with Create React App
28+
29+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
30+
31+
## Available Scripts
32+
33+
In the project directory, you can run:
34+
35+
### `npm start`
36+
37+
Runs the app in the development mode.\
38+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
39+
40+
The page will reload if you make edits.\
41+
You will also see any lint errors in the console.
42+
43+
### `npm test`
44+
45+
Launches the test runner in the interactive watch mode.\
46+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
47+
48+
### `npm run build`
49+
50+
Builds the app for production to the `build` folder.\
51+
It correctly bundles React in production mode and optimizes the build for the best performance.
52+
53+
The build is minified and the filenames include the hashes.\
54+
Your app is ready to be deployed!
55+
56+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
57+
58+
### `npm run eject`
59+
60+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
61+
62+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
63+
64+
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
65+
66+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
67+
68+
## Learn More
69+
70+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
71+
72+
To learn React, check out the [React documentation](https://reactjs.org/).

examples/typescript/package.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "typescript",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@testing-library/jest-dom": "^5.16.5",
7+
"@testing-library/react": "^13.4.0",
8+
"@testing-library/user-event": "^13.5.0",
9+
"@types/jest": "^27.5.2",
10+
"@types/node": "^16.18.18",
11+
"@types/react": "^18.0.28",
12+
"@types/react-dom": "^18.0.11",
13+
"launchdarkly-react-client-sdk": "^3.0.4",
14+
"react": "^18.2.0",
15+
"react-dom": "^18.2.0",
16+
"react-scripts": "5.0.1",
17+
"typescript": "^4.9.5",
18+
"web-vitals": "^2.1.4"
19+
},
20+
"scripts": {
21+
"analyze": "source-map-explorer 'build/static/js/*.js'",
22+
"start": "react-scripts start",
23+
"build": "react-scripts build",
24+
"test": "react-scripts test",
25+
"eject": "react-scripts eject"
26+
},
27+
"eslintConfig": {
28+
"extends": [
29+
"react-app",
30+
"react-app/jest"
31+
]
32+
},
33+
"browserslist": {
34+
"production": [
35+
">0.2%",
36+
"not dead",
37+
"not op_mini all"
38+
],
39+
"development": [
40+
"last 1 chrome version",
41+
"last 1 firefox version",
42+
"last 1 safari version"
43+
]
44+
},
45+
"devDependencies": {
46+
"source-map-explorer": "2.5.3"
47+
}
48+
}

examples/typescript/src/App.css

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.App {
2+
text-align: center;
3+
}
4+
5+
.App-logo {
6+
height: 40vmin;
7+
pointer-events: none;
8+
}
9+
10+
@media (prefers-reduced-motion: no-preference) {
11+
.App-logo {
12+
animation: App-logo-spin infinite 20s linear;
13+
}
14+
}
15+
16+
.App-header {
17+
background-color: #282c34;
18+
min-height: 100vh;
19+
display: flex;
20+
flex-direction: column;
21+
align-items: center;
22+
justify-content: center;
23+
font-size: calc(10px + 2vmin);
24+
color: white;
25+
}
26+
27+
.App-link {
28+
color: #61dafb;
29+
}
30+
31+
@keyframes App-logo-spin {
32+
from {
33+
transform: rotate(0deg);
34+
}
35+
to {
36+
transform: rotate(360deg);
37+
}
38+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import App from './App';
4+
5+
test('renders learn react link', () => {
6+
render(<App />);
7+
const linkElement = screen.getByText(/learn react/i);
8+
expect(linkElement).toBeInTheDocument();
9+
});

examples/typescript/src/App.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
import logo from './logo.svg';
3+
import './App.css';
4+
import { useFlags } from 'launchdarkly-react-client-sdk';
5+
6+
function App() {
7+
const { devTestFlag } = useFlags();
8+
9+
return (
10+
<div className="App">
11+
<header className="App-header">
12+
<img src={logo} className="App-logo" alt="logo" />
13+
<p>{devTestFlag ? <b>Flag on</b> : <b>Flag off</b>}</p>
14+
<a className="App-link" href="https://reactjs.org" target="_blank" rel="noopener noreferrer">
15+
Learn React
16+
</a>
17+
</header>
18+
</div>
19+
);
20+
}
21+
22+
export default App;

examples/typescript/src/index.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
body {
2+
margin: 0;
3+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4+
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5+
sans-serif;
6+
-webkit-font-smoothing: antialiased;
7+
-moz-osx-font-smoothing: grayscale;
8+
}
9+
10+
code {
11+
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12+
monospace;
13+
}

examples/typescript/src/index.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom/client';
3+
import './index.css';
4+
import App from './App';
5+
import reportWebVitals from './reportWebVitals';
6+
import { asyncWithLDProvider } from 'launchdarkly-react-client-sdk';
7+
8+
(async () => {
9+
// Set clientSideID to your own Client-side ID. You can find this in
10+
// your LaunchDarkly portal under Account settings / Projects
11+
const LDProvider = await asyncWithLDProvider({
12+
clientSideID: process.env.REACT_APP_LD_CLIENT_SIDE_ID ?? '',
13+
});
14+
15+
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
16+
root.render(
17+
<React.StrictMode>
18+
<LDProvider>
19+
<App />
20+
</LDProvider>
21+
</React.StrictMode>,
22+
);
23+
24+
// If you want to start measuring performance in your app, pass a function
25+
// to log results (for example: reportWebVitals(console.log))
26+
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
27+
reportWebVitals();
28+
})();

examples/typescript/src/logo.svg

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="react-scripts" />

0 commit comments

Comments
 (0)