Skip to content

Commit

Permalink
Merge pull request #18 from arkahna/fix/infinite-re-renders
Browse files Browse the repository at this point in the history
Fixing infinite re-renders, the subscription triggers a set state, wh…
  • Loading branch information
JakeGinnivan authored Jul 24, 2023
2 parents 89e2bc2 + 9d45762 commit 6e3f800
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tricky-meals-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@featureboard/react-sdk': patch
---

Check to see if value has changed before setting state
2 changes: 1 addition & 1 deletion libs/react-sdk/src/use-feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function useFeature<T extends keyof Features>(
return fbContext.client.subscribeToFeatureValue(
featureKey,
defaultValue,
(value) => setValue(value),
(newValue) => newValue !== value && setValue(newValue),
)
})

Expand Down

0 comments on commit 6e3f800

Please sign in to comment.