Skip to content

Commit

Permalink
docs: rename parameters related to feature name
Browse files Browse the repository at this point in the history
  • Loading branch information
Tymek committed Jan 9, 2024
1 parent ad1b80c commit 0c52040
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/useFlag.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { useContext, useEffect, useState, useRef } from 'react';
import FlagContext from './FlagContext';

const useFlag = (name: string) => {
const useFlag = (featureName: string) => {
const { isEnabled, client } = useContext(FlagContext);
const [flag, setFlag] = useState(!!isEnabled(name));
const [flag, setFlag] = useState(!!isEnabled(featureName));
const flagRef = useRef<typeof flag>();
flagRef.current = flag;

useEffect(() => {
if (!client) return;

const updateHandler = () => {
const enabled = isEnabled(name);
const enabled = isEnabled(featureName);
if (enabled !== flagRef.current) {
flagRef.current = enabled;
setFlag(!!enabled);
}
};

const readyHandler = () => {
const enabled = isEnabled(name);
const enabled = isEnabled(featureName);
flagRef.current = enabled;
setFlag(enabled);
};
Expand Down
8 changes: 4 additions & 4 deletions src/useVariant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export const variantHasChanged = (
return !variantsAreEqual;
};

const useVariant = (name: string): Partial<IVariant> => {
const useVariant = (featureName: string): Partial<IVariant> => {
const { getVariant, client } = useContext(FlagContext);

const [variant, setVariant] = useState(getVariant(name));
const [variant, setVariant] = useState(getVariant(featureName));
const variantRef = useRef<typeof variant>({
name: variant.name,
enabled: variant.enabled,
Expand All @@ -30,15 +30,15 @@ const useVariant = (name: string): Partial<IVariant> => {
if (!client) return;

const updateHandler = () => {
const newVariant = getVariant(name);
const newVariant = getVariant(featureName);
if (variantHasChanged(variantRef.current, newVariant)) {
setVariant(newVariant);
variantRef.current = newVariant;
}
};

const readyHandler = () => {
const variant = getVariant(name);
const variant = getVariant(featureName);
variantRef.current.name = variant?.name;
variantRef.current.enabled = variant?.enabled;
setVariant(variant);
Expand Down

0 comments on commit 0c52040

Please sign in to comment.