marvelapp / react-ab-test

A/B testing React components and debug tools. Isomorphic with a simple, universal interface. Well documented and lightweight. Tested in popular browsers and Node.js. Includes helpers for Mixpanel and Segment.com.
MIT License
240 stars 47 forks source link

Support for Hooks? #8

Closed tbrannam closed 2 years ago

tbrannam commented 4 years ago

Have folks investigated updating to prepare for React Lifecycle event deprecation, and supporting React Hooks?

Thanks for maintaining this fork.

moretti commented 4 years ago

Hey @tbrannam, thank you for your message!

So, the first task is to make react-ab-test compatible with the upcoming React 17.0, by either:

Supporting hooks requires more discussion, for example I don't know if they would fit better in a separate / complementary library based on the core lib, or perhaps in a different entry point (eg. import { useExperiment } from '@marvelapp/react-ab-test/hooks') . 🤔

tbrannam commented 4 years ago

Trying to think through how hooks might work - have a simple concept here:

https://codesandbox.io/s/react-ab-test-hooks-1qd20 https://github.com/tbrannam/react-ab-test-hooks

moretti commented 4 years ago

This is amazing, the API is so much cleaner! I'm thinking that we could also provide a helper similar to react-native's Platform.select, eg:

emitter.defineVariants('experiment-name', ['var1', 'var2']);
function Experiment() {
  const { selectVariant, emitWin } = useExperiment('experiment-name');

  const variantName = selectVariant({
    var1: 'Variant 1',
    var2: 'Variant 2',
  });

  return (
    <>
      <div>{variantName}</div>
      <button onClick={emitWin}>Emit win</button>
    </>
  );
}
tbrannam commented 4 years ago

That looks cool - I updated my POC

tbrannam commented 4 years ago

I'm looking at refactoring CoreExperiment to be a functional component that is implemented using the hook instead of having two parallel implementations - and it's mostly coming together pretty well. As part of the implementation - I may change the props to CoreExperiment to to be more like Experiment - as CoreExperiments new function is mostly to act as FC adapter to the Hook.

Any concerns?

moretti commented 4 years ago

@tbrannam nice one! Feel free to submit a PR, or post a link your branch 🙂 Did you find a solution for replacing CoreExperiment.componentWillMount with hooks?

tbrannam commented 4 years ago

So I'm pretty far along now - I've integrated my POC into a fork. I've got some tests to write for the hook - and some documentation updates as well. I found another way to resolve the testing requirements for SSR rendering.

The big callouts in my fork is CoreExperiment.jsx and hooks.jsx

https://github.com/tbrannam/react-ab-test/tree/hooks-refactor

tbrannam commented 4 years ago

10

tbrannam commented 3 years ago

It's been awhile - any chance we can get the hooks released outside of a beta tag?

vitorhugo-anjos commented 3 years ago

Indeed it would be great hooks released

gregegan commented 3 years ago

Following up here. Is this a dead project?

rtrembecky commented 3 years ago

another bump. @moretti is this releasable outside of beta? I'll use beta tag for now.

tbrannam commented 3 years ago

Closing, This seems to be in master branch.

rtrembecky commented 3 years ago

Closing, This seems to be in master branch.

@tbrannam this is in master for a long time already. the problem is the npm package was last published 2 years ago with version 2.3.0. if you want hooks, you need to use 3.0.0-beta.0 version. can anybody publish this as a stable package version?

tbrannam commented 3 years ago

Oh that is disappointing. I don't have an inside track with Marvel.

tbrannam commented 3 years ago

@moretti Is there any chance that the 3.0 could be released as a stable version?

moretti commented 3 years ago

@tbrannam @rtrembecky I'm sorry, my Github notifications were disabled for this repo. Unfortunately we are not actively using this module anymore, which is the main reason why it was not maintained for the past year. I just published a new version 3.0.0, which adds support for hooks (outside of the beta tag) and is compatible with React 17.