Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
f5ccadf0
Commit
f5ccadf0
authored
Jan 11, 2024
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better typing
parent
2c18ad2f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
6 deletions
+13
-6
init.ts
lib/growthbook/init.ts
+5
-1
useFeatureValue.ts
lib/growthbook/useFeatureValue.ts
+7
-4
useInit.tsx
lib/mixpanel/useInit.tsx
+1
-1
No files found.
lib/growthbook/init.ts
View file @
f5ccadf0
...
@@ -3,6 +3,10 @@ import { GrowthBook } from '@growthbook/growthbook-react';
...
@@ -3,6 +3,10 @@ import { GrowthBook } from '@growthbook/growthbook-react';
import
config
from
'
configs/app
'
;
import
config
from
'
configs/app
'
;
import
*
as
mixpanel
from
'
lib/mixpanel
'
;
import
*
as
mixpanel
from
'
lib/mixpanel
'
;
export
interface
GrowthBookFeatures
{
test_value
:
string
;
}
export
const
growthBook
=
(()
=>
{
export
const
growthBook
=
(()
=>
{
const
feature
=
config
.
features
.
growthBook
;
const
feature
=
config
.
features
.
growthBook
;
...
@@ -10,7 +14,7 @@ export const growthBook = (() => {
...
@@ -10,7 +14,7 @@ export const growthBook = (() => {
return
;
return
;
}
}
return
new
GrowthBook
({
return
new
GrowthBook
<
GrowthBookFeatures
>
({
apiHost
:
'
https://cdn.growthbook.io
'
,
apiHost
:
'
https://cdn.growthbook.io
'
,
clientKey
:
feature
.
clientKey
,
clientKey
:
feature
.
clientKey
,
enableDevMode
:
config
.
app
.
isDev
,
enableDevMode
:
config
.
app
.
isDev
,
...
...
lib/growthbook/useFeatureValue.ts
View file @
f5ccadf0
import
type
{
WidenPrimitives
}
from
'
@growthbook/growthbook
'
;
import
{
useFeatureValue
,
useGrowthBook
}
from
'
@growthbook/growthbook-react
'
;
import
{
useFeatureValue
,
useGrowthBook
}
from
'
@growthbook/growthbook-react
'
;
export
default
function
useGbFeatureValue
<
T
extends
Parameters
<
typeof
useFeatureValue
>
[
1
]
>
(
import
type
{
GrowthBookFeatures
}
from
'
./init
'
;
name
:
Parameters
<
typeof
useFeatureValue
>
[
0
],
fallback
:
T
,
export
default
function
useGbFeatureValue
<
Name
extends
keyof
GrowthBookFeatures
>
(
):
{
value
:
ReturnType
<
typeof
useFeatureValue
<
T
>>
;
isLoading
:
boolean
}
{
name
:
Name
,
fallback
:
GrowthBookFeatures
[
Name
],
):
{
value
:
WidenPrimitives
<
GrowthBookFeatures
[
Name
]
>
;
isLoading
:
boolean
}
{
const
value
=
useFeatureValue
(
name
,
fallback
);
const
value
=
useFeatureValue
(
name
,
fallback
);
const
growthBook
=
useGrowthBook
();
const
growthBook
=
useGrowthBook
();
...
...
lib/mixpanel/useInit.tsx
View file @
f5ccadf0
...
@@ -30,7 +30,7 @@ export default function useMixpanelInit() {
...
@@ -30,7 +30,7 @@ export default function useMixpanelInit() {
loaded
:
function
()
{
loaded
:
function
()
{
growthBook
?.
setAttributes
({
growthBook
?.
setAttributes
({
...
growthBook
.
getAttributes
(),
...
growthBook
.
getAttributes
(),
time
_
zone
:
Intl
.
DateTimeFormat
().
resolvedOptions
().
timeZone
,
timezone
:
Intl
.
DateTimeFormat
().
resolvedOptions
().
timeZone
,
language
:
window
.
navigator
.
language
,
language
:
window
.
navigator
.
language
,
});
});
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment