-
Notifications
You must be signed in to change notification settings - Fork 118
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
Comments
Yes Please |
I have setup with a react context and hooks - suppose I can share it if this is still of interest? |
@tobiaseisenschenk: Would be helpful for folks if you can share a snippet of the same. Thanks, |
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; |
If anyone is using this library with react hooks and can provide a simple example then it will really helpful.
The text was updated successfully, but these errors were encountered: