Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: rename parameters related to feature name #156

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading