-
Notifications
You must be signed in to change notification settings - Fork 12
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
[Feature request] useTreatment and useTreatmentWithConfig hooks #69
Comments
Hi @besh , did you check the doc page? We do have an example for the SDK using react hooks: https://help.split.io/hc/en-us/articles/360038825091-React-SDK#using-the-sdk See below, the featureName is set to one split name, and the treatment returned is only for one split: mport { useContext } from 'react';
|
@chillaq, thank you. I did see that example. However, I want to add a I'll have some time tomorrow to push up a PR for the team to review. |
Draft PR: #70 |
Hi @besh , Thank you for your suggestion and draft PR. We will take it into account, but we cannot prioritize that work at the moment. For your information, we have provided only one version of Any other "hook" variant can be simply derived from the provided one. For instance, the hook equivalent to const useTreatment = (splitName: string, attributes?: SplitIO.Attributes, key?: SplitIO.SplitKey): SplitIO.Treatment => {
return useTreatments([splitName], attributes, key)[splitName].treatment;
} The one for const useTreatmentWithConfig = (splitName: string, attributes?: SplitIO.Attributes, key?: SplitIO.SplitKey): SplitIO.TreatmentWithConfig => {
return useTreatments([splitName], attributes, key)[splitName];
} and so on. |
@EmilianoSanchez understood. Aw. I was hoping to get these hooks into the core package to bring about feature parity with the other SDKs instead of having our own wrapping package. However, if this is not something that would benefit the Split community, then I suppose that may be our only option. Is it work you'd like to prioritize in the future? I certainly don't mind finalizing my PR and prepping it for then. |
Hi @besh
Yes, we will prioritize it in the future, but for consistency we consider that this change should be done as a breaking change (v2.0.0), because the current So, we will consider your suggestion and retake your PR in the future, but there is not an ETA yet for the next major release. |
@EmilianoSanchez Got it, and thank you for the response. When you're ready, I'd be happy to help in the future. For now, we wrote a little wrapper lib. We found that most of our historical use cases of feature flags (maybe even all) were simple on/off. With that, we created a simplified hook to return a boolean to avoid string equality checking. type UseFeatureFlagOptions = {
attributes?: SplitIO.Attributes;
key?: SplitIO.SplitKey;
variantName?: string;
};
const useFeatureFlag = (flagName: string, options?: UseFeatureFlagOptions): boolean => {
const { variantName, attributes, key }: UseFeatureFlagOptions = {
variantName: 'on',
...options,
};
const flag = useTreatments([flagName], attributes, key)[flagName];
return flag && flag.treatment === variantName;
}; In most cases, we would just do I know this is somewhat unaligned with the "everything is a string" approach with Split, but I did submit a feature request to allow Split users to specify the split "type" in the Split.io dashboard. It would be a neat thing to support in the future. |
Thanks for sharing your snippet @besh - It might be useful for me too. |
For our team's use case, we often want to get a single split and its treatments. It seems that getTreatment and getTreatmentWithConfig from the underlying javascript-SDK are not currently available as React hooks, but I may have overlooked it in the codebase!
Here's the API I'm thinking of.
Would you be open to me submitting a PR for this? Thank you!
The text was updated successfully, but these errors were encountered: