Skip to content

Commit 80f04ce

Browse files
authored
chore: Migrate flagsmith to @Flagsmith/flagsmith and @flagsmith/react-native (#6924)
1 parent dbd66e9 commit 80f04ce

15 files changed

Lines changed: 46 additions & 54 deletions

File tree

docs/docs/integrating-with-flagsmith/sdks/client-side-sdks/javascript.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Example applications for a variety of JavaScript frameworks such as React, Vue a
1515
### NPM
1616

1717
```bash
18-
npm i flagsmith --save
18+
npm i @flagsmith/flagsmith --save
1919
```
2020

2121
### NPM for React Native
@@ -29,7 +29,7 @@ AsyncStorage to be provided (e.g. @react-native-community/async-storage) in orde
2929
:::
3030

3131
```bash
32-
npm i react-native-flagsmith --save
32+
npm i @flagsmith/react-native --save
3333
```
3434

3535
## Basic Usage
@@ -41,7 +41,7 @@ settings page.
4141
### Example: Initialising the SDK
4242

4343
```javascript
44-
import flagsmith from 'flagsmith or react-native-flagsmith'; //Add this line if you're using flagsmith via npm
44+
import flagsmith from '@flagsmith/flagsmith or @flagsmith/react-native'; //Add this line if you're using flagsmith via npm
4545

4646
flagsmith.init({
4747
environmentID: '<YOUR_CLIENT_SIDE_ENVIRONMENT_KEY>',
@@ -82,7 +82,7 @@ You can define default flag values when initialising the SDK. This ensures that
8282
the event that it [cannot receive a response from our API](/best-practices/defensive-coding).
8383

8484
```javascript
85-
import flagsmith from 'flagsmith or react-native-flagsmith'; //Add this line if you're using flagsmith via npm
85+
import flagsmith from '@flagsmith/flagsmith or @flagsmith/react-native'; //Add this line if you're using flagsmith via npm
8686

8787
try {
8888
flagsmith.init({
@@ -136,7 +136,7 @@ When you initialise the client without an identity, it will fetch the flags for
136136
`preventFetch:true`).
137137

138138
```javascript
139-
import flagsmith from 'flagsmith';
139+
import flagsmith from '@flagsmith/flagsmith';
140140

141141
flagsmith.init({
142142
environmentID: '<YOUR_CLIENT_SIDE_ENVIRONMENT_KEY>',
@@ -170,7 +170,7 @@ flagsmith.init({
170170
});
171171

172172
/*
173-
Can be called either after you're done initialising the project or in flagsmith.init with its identity and trait properties
173+
Can be called either after you're done initialising the project or in flagsmith.init with its identity and trait properties
174174
to prevent flags being fetched twice.
175175
*/
176176
flagsmith.identify('flagsmith_sample_user'); //This will create a user in the dashboard if they don't already exist
@@ -182,7 +182,7 @@ Initialising the client with an identity property will retrieve the user's flags
182182
You can also specify traits at this point which could determine the flags that come back based on segment overrides.
183183

184184
```javascript
185-
import flagsmith from 'flagsmith';
185+
import flagsmith from '@flagsmith/flagsmith';
186186

187187
flagsmith.init({
188188
environmentID: '<YOUR_CLIENT_SIDE_ENVIRONMENT_KEY>',
@@ -279,7 +279,7 @@ export function createFlagsmithInstance (): IFlagsmith
279279
Usage:
280280

281281
```javascript
282-
import { createFlagsmithInstance } from 'flagsmith';
282+
import { createFlagsmithInstance } from '@flagsmith/flagsmith';
283283
const flagsmith = createFlagsmithInstance();
284284
const flagsmithB = createFlagsmithInstance();
285285

@@ -340,7 +340,7 @@ We can now enforce these types:
340340

341341
```typescript
342342
// enforces you passing the correct key to flagsmith.getValue(flag:FlagOptions), flagsmith.getTrait(trait:TraitOptions)
343-
import flagsmith from 'flagsmith';
343+
import flagsmith from '@flagsmith/flagsmith';
344344
const typedFlagsmith = flagsmith as IFlagsmith<FlagOptions, TraitOptions>;
345345

346346
// Similarly for the useFlagsmith hook is typed with useFlagsmith(flags:FlagOptions[],traits:TraitOptions[])

docs/docs/integrating-with-flagsmith/sdks/client-side-sdks/nextjs-and-ssr.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ An example application for Next.js middleware can be found
2323
### NPM
2424

2525
```bash
26-
npm i flagsmith --save
26+
npm i @flagsmith/flagsmith --save
2727
```
2828

2929
## Basic Usage
@@ -34,7 +34,7 @@ settings page.
3434
## Comparing SSR and client-side Flagsmith usage
3535

3636
The SDK is initialised and used in the same way as the [JavaScript](/integrating-with-flagsmith/sdks/client-side-sdks/javascript) and [React](/integrating-with-flagsmith/sdks/client-side-sdks/react)
37-
SDK. The main difference is that Flagsmith should be imported from `flagsmith/isomorphic`.
37+
SDK. The main difference is that Flagsmith should be imported from `@flagsmith/flagsmith/isomorphic`.
3838

3939
The main flow with Next.js and any JavaScript-based SSR can be as follows:
4040

@@ -56,9 +56,9 @@ state. Below is an example for the **app** router as well as the **pages** route
5656

5757
import { ReactNode, useRef } from "react";
5858

59-
import { FlagsmithProvider } from "flagsmith/react";
60-
import { IState } from "flagsmith/types";
61-
import { createFlagsmithInstance } from "flagsmith/isomorphic";
59+
import { FlagsmithProvider } from "@flagsmith/flagsmith/react";
60+
import { IState } from "@flagsmith/flagsmith/types";
61+
import { createFlagsmithInstance } from "@flagsmith/flagsmith/isomorphic";
6262

6363
export const FeatureFlagProvider = ({
6464
serverState,
@@ -79,7 +79,7 @@ export const FeatureFlagProvider = ({
7979
// src/app/layout.jsx
8080
import { ReactNode } from "react";
8181
import { FeatureFlagProvider } from './components/FeatureFlagProvider';
82-
import flagsmith from "flagsmith/isomorphic";
82+
import flagsmith from "@flagsmith/flagsmith/isomorphic";
8383

8484
export default async function RootLayout({
8585
children,
@@ -111,8 +111,8 @@ export default async function RootLayout({
111111

112112
```javascript
113113
// src/pages/_app.jsx
114-
import { FlagsmithProvider } from 'flagsmith/react';
115-
import { createFlagsmithInstance } from 'flagsmith/isomorphic';
114+
import { FlagsmithProvider } from '@flagsmith/flagsmith/react';
115+
import { createFlagsmithInstance } from '@flagsmith/flagsmith/isomorphic';
116116
function MyApp({ Component, pageProps, flagsmithState }) {
117117
const flagsmithRef = useRef(createFlagsmithInstance());
118118
return (
@@ -140,7 +140,7 @@ export default MyApp;
140140
```javascript
141141
'use client'; // Only required by the app router version.
142142

143-
import { useFlags } from 'flagsmith/react';
143+
import { useFlags } from '@flagsmith/flagsmith/react';
144144

145145
export function MyComponent() {
146146
const flags = useFlags(['font_size'], ['example_trait']); // only causes re-render if specified flag values / traits change
@@ -157,14 +157,14 @@ From this point on, the SDK usage is the same as the [React SDK Guide](/integrat
157157

158158
### Example: Flagsmith with Next.js middleware
159159

160-
The Flagsmith JS client includes `flagsmith/next-middleware`, it can be used just like the regular library within
160+
The Flagsmith JS client includes `@flagsmith/flagsmith/next-middleware`, it can be used just like the regular library within
161161
Next.js middleware.
162162

163163
```javascript
164164
// middleware.ts
165165
import { NextResponse } from 'next/server';
166166
import type { NextRequest } from 'next/server';
167-
import flagsmith from 'flagsmith/next-middleware';
167+
import flagsmith from '@flagsmith/flagsmith/next-middleware';
168168

169169
export async function middleware(request: NextRequest) {
170170
const identity = request.cookies.get('user');

docs/docs/integrating-with-flagsmith/sdks/client-side-sdks/react.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Example applications for a variety of React, React Native and Next.js can be fou
1818
### NPM
1919

2020
```bash
21-
npm i flagsmith --save
21+
npm i @flagsmith/flagsmith --save
2222
```
2323

2424
### NPM for React Native
@@ -32,7 +32,7 @@ AsyncStorage to be provided (e.g. @react-native-community/async-storage) in orde
3232
:::
3333

3434
```bash
35-
npm i react-native-flagsmith --save
35+
npm i @flagsmith/react-native --save
3636
```
3737

3838
## Basic Usage
@@ -46,8 +46,8 @@ Wrapping your application with our FlagsmithProvider component provides a React
4646
that you can use the hooks `useFlagsmith` and `useFlags`.
4747

4848
```javascript
49-
import flagsmith from 'flagsmith'
50-
import {FlagsmithProvider} from 'flagsmith/react'
49+
import flagsmith from '@flagsmith/flagsmith'
50+
import {FlagsmithProvider} from '@flagsmith/flagsmith/react'
5151

5252
export function AppRoot() {
5353
<FlagsmithProvider options={{
@@ -75,7 +75,7 @@ Components that have been wrapped in a FlagsmithProvider will be able to evaluat
7575
well as user traits via the `useFlags` hook.
7676

7777
```javascript
78-
import { useFlags } from 'flagsmith/react';
78+
import { useFlags } from '@flagsmith/flagsmith/react';
7979

8080
export function MyComponent() {
8181
const flags = useFlags(['font_size'], ['example_trait']); // only causes re-render if specified flag values / traits change
@@ -112,7 +112,7 @@ Components that have been wrapped in a FlagsmithProvider will be able to access
112112

113113
```javascript
114114
import React from 'react';
115-
import { useFlags, useFlagsmith } from 'flagsmith/react';
115+
import { useFlags, useFlagsmith } from '@flagsmith/flagsmith/react';
116116

117117
export function MyComponent() {
118118
const flags = useFlags(['font_size'], ['example_trait']); // only causes re-render if specified flag values / traits change

frontend/.claude/context/feature-flags/feature-flags.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class MyClassComponent extends Component {
7171
For reference, the project also supports direct `useFlags` hook, but **Utils.getFlagsmithHasFeature is preferred**:
7272

7373
```typescript
74-
import { useFlags } from 'flagsmith/react'
74+
import { useFlags } from '@flagsmith/flagsmith/react'
7575

7676
const MyComponent = () => {
7777
const flags = useFlags(['feature_name'])

frontend/.claude/context/ui-patterns.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const MyPage = () => {
9898
When specifically requested, this pattern shows tabs only when feature flag is enabled:
9999

100100
```typescript
101-
import { useFlags } from 'flagsmith/react'
101+
import { useFlags } from '@flagsmith/flagsmith/react'
102102
import { Tabs } from 'components/base/forms/Tabs'
103103
import Utils from 'common/utils/utils'
104104
const MyPage = () => {

frontend/common/code-help/create-user/create-user-next.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = (
77
// Option 1: Identify clientside
88
//Home Page
99
import flagsmith from '${LIB_NAME}/isomorphic';
10-
import { useFlags, useFlagsmith } from 'flagsmith/react';
10+
import { useFlags, useFlagsmith } from '@flagsmith/flagsmith/react';
1111
1212
export default function HomePage() {
1313
const flags = useFlags(['${FEATURE_NAME}','${FEATURE_NAME_ALT}']); // only causes re-render if specified flag values / traits change

frontend/common/code-help/init/init-next-app-router.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ export default async function RootLayout({
3838
"use client";
3939
4040
import { ReactNode, useRef } from "react";
41-
import { FlagsmithProvider } from "flagsmith/react";
42-
import { IState } from "flagsmith/types";
43-
import { createFlagsmithInstance } from "flagsmith/isomorphic";
41+
import { FlagsmithProvider } from "@flagsmith/flagsmith/react";
42+
import { IState } from "@flagsmith/flagsmith/types";
43+
import { createFlagsmithInstance } from "@flagsmith/flagsmith/isomorphic";
4444
4545
export const FeatureFlagProvider = ({
4646
serverState,
@@ -61,7 +61,7 @@ export const FeatureFlagProvider = ({
6161
// app/page.tsx
6262
"use client";
6363
64-
import { useFlags } from 'flagsmith/react';
64+
import { useFlags } from '@flagsmith/flagsmith/react';
6565
6666
export default function HomePage() {
6767
const flags = useFlags(['${FEATURE_NAME}','${FEATURE_NAME_ALT}']); // only causes re-render if specified flag values / traits change

frontend/common/code-help/init/init-next-pages-router.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = (
44
{ FEATURE_NAME, FEATURE_NAME_ALT, LIB_NAME, NPM_CLIENT },
55
) => `// pages/_app.js
66
import ${LIB_NAME} from "${NPM_CLIENT}/isomorphic";
7-
import { FlagsmithProvider } from 'flagsmith/react';
7+
import { FlagsmithProvider } from '@flagsmith/flagsmith/react';
88
99
export default function App({ Component, pageProps, flagsmithState } {
1010
return (
@@ -35,8 +35,8 @@ App.getInitialProps = async () => {
3535
}
3636
3737
// pages/index.js
38-
import flagsmith from 'flagsmith/isomorphic';
39-
import { useFlags, useFlagsmith } from 'flagsmith/react';
38+
import flagsmith from '@flagsmith/flagsmith/isomorphic';
39+
import { useFlags, useFlagsmith } from '@flagsmith/flagsmith/react';
4040
4141
export default function HomePage() {
4242
const flags = useFlags(['${FEATURE_NAME}','${FEATURE_NAME_ALT}']); // only causes re-render if specified flag values / traits change

frontend/common/code-help/init/init-react.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = (
55
{ FEATURE_NAME, FEATURE_NAME_ALT, LIB_NAME, NPM_CLIENT },
66
) => `// App root
77
import ${LIB_NAME} from "${NPM_CLIENT}";
8-
import { FlagsmithProvider } from 'flagsmith/react';
8+
import { FlagsmithProvider } from '@flagsmith/flagsmith/react';
99
1010
export default function App() {
1111
return (

frontend/common/code-help/traits/traits-next.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = (
77
// Option 1: Identify clientside
88
//Home Page
99
import flagsmith from '${LIB_NAME}/isomorphic';
10-
import { useFlags, useFlagsmith } from 'flagsmith/react';
10+
import { useFlags, useFlagsmith } from '@flagsmith/flagsmith/react';
1111
1212
export default function HomePage() {
1313
const flags = useFlags(['${FEATURE_NAME}','${FEATURE_NAME_ALT}']); // only causes re-render if specified flag values / traits change

0 commit comments

Comments
 (0)