react-vary 🐱 😸 😽 😻 😹
Statically and Dynamically declare variants for AB testing react components.
Same Top-level API as prop-types. Declare brand new components as variants or override render behavior pre-existing components.
;;; // The Component that receives the variants will be considered default (variant 0)Component { const props = this; return <div>Variant: thispropsvariant</div> }MyCompvariants = 1: MyComp1 2: MyComp2 const MyCompWithVariants = ; // However you determine variants is up to you// Just pass the known variant number down through the parent HOC to render the variant ChildComponent { return <div> /* Variant 0 is our default Component defined above */ <MyCompWithVariants variant=0 /> /* Non-0 variants map directly to MyComp.variants */ <MyCompWithVariants variant=1 /> <MyCompWithVariants variant=2 /> /* Wtih render prop components we get all the state updates of variant 0 but with a custom render override. All without touching our original component! */ <MyCompWithVariants variant=3 render= { return <div>DisplayName: displayName Variant: variant</div>; } /> </div> ; }
By passing a component to WithVariants
you get an HOC wrapper back that passes data about your variants via props. Each variant receives the following props.
/** * @param * @param * @param * @param * @param * @param * @param * @param * @param * * @param */
More Examples