In react, I am using @apollo/client for backend APIs. In appollo.js I am trying to call backend API link based on condition.
Right now appollo.js contains only functions, its not a component.
I am trying add statsig feature to it, const featureOn = useGate(<FEATURE_GATE_NAME>).value;
How can I use statsig variable inside appollo.js?
Also I have tried by creating separate component and rendering like <AbcComponent />, but its not return a required value.
AbcComponent.js,
export const AbcComponent = () => {
const featureOn = useGate('abc').value
return featureOn ? 'Yes' : 'no'
}
In this scenario, how can I get 'Yes/No' from appollo.js?
Component in react should always return a JSX . what you need here is a custom hook.
export const useCheckFeatureOn = () => {
const featureOn = useGate('abc').value
return featureOn ? 'Yes' : 'no'
}
Use the above hook wherever you want to consume the value
const isFeatureOn = useCheckFeatureOn();