Skip to content

Commit

Permalink
feat: add a useTreatment hook
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Sep 3, 2020
1 parent 503e3c6 commit e9c8aac
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/hooks/useTreatment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useMemo } from 'react';
import { useTreatments } from '@splitsoftware/splitio-react';

const useTreatment = (name) => {
const treatments = useTreatments([name]);
const { treatment, config } = treatments[name];

return {
treatment,
config: useMemo(() => {
try {
return JSON.parse(config);
} catch (e) {
return {};
}
}, [config]),
};
};

export default useTreatment;

0 comments on commit e9c8aac

Please sign in to comment.