Skip to content
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

Functional component example with hooks #117

Open
ShivamJoker opened this issue May 3, 2021 · 4 comments
Open

Functional component example with hooks #117

ShivamJoker opened this issue May 3, 2021 · 4 comments

Comments

@ShivamJoker
Copy link

If anyone is using this library with react hooks and can provide a simple example then it will really helpful.

@Rushil10
Copy link

Yes Please

@tobiaseisenschenk
Copy link

I have setup with a react context and hooks - suppose I can share it if this is still of interest?

@prscX
Copy link
Owner

prscX commented Apr 9, 2022

@tobiaseisenschenk: Would be helpful for folks if you can share a snippet of the same.

Thanks,
Pranav

@brownieboy
Copy link

brownieboy commented May 14, 2022

I had a go at converting the Example/App.js over to functional component and hooks. I got it kind of working, but as I got deeper into it, I decided that this library wasn't for me.

I'll leave it here in case it's of any help to others though.

// imports and styles not shown.  Keep the same as in current code.

const App = () => {
  const appTourTargets = useRef([]);

  useEffect(() => {
    DeviceEventEmitter.addListener(
      'event',
      'onShowSequenceStepEvent',
      (e: Event) => {
        console.log(e);
      },
    );

    DeviceEventEmitter.addListener(
      'event',
      'finishSequenceListener',
      (e: Event) => {
        console.log(e);
      },
    );

    return () => {
      DeviceEventEmitter.removeListener('event', 'onShowSequenceStepEvent');
      DeviceEventEmitter.removeListener('event', 'finishSequenceListener');
    };
  }, []); // No params, so runs only once (like ComponentDidMount)

  useLayoutEffect(() => {
    setTimeout(() => {
      let appTourSequence = new AppTourSequence();
      appTourTargets.current.forEach(appTourTarget => {
        appTourSequence.add(appTourTarget);
      });

      AppTour.ShowSequence(appTourSequence);
    }, 1000);
  }, [appTourTargets]);

  return (
    <View style={styles.container}>
      <Top
        style={styles.top}
        addAppTourTarget={appTourTarget => {
          appTourTargets.current.push(appTourTarget);
        }}
      />
      <Center
        style={styles.center}
        addAppTourTarget={appTourTarget => {
          appTourTargets.current.push(appTourTarget);
        }}
      />
      <Bottom
        style={styles.bottom}
        addAppTourTarget={appTourTarget => {
          appTourTargets.current.push(appTourTarget);
        }}
      />
    </View>
  );
};

export default App;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants