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

Autostart on mount #287

Open
Zeeshan10277 opened this issue May 30, 2023 · 9 comments
Open

Autostart on mount #287

Zeeshan10277 opened this issue May 30, 2023 · 9 comments

Comments

@Zeeshan10277
Copy link

Whenever i try to start the tour from useEffect, It does'nt work even if am passing setTimeout to it. Example code is given below:

const tour = useCopilot()
useEffect(()=>{
setTimeout(()=>{
tour.start("repaircat");
}, 600)
},[])

In the first screen I have started the tour by passing start() to the button click but in the second screen i want to initiate the tour again by calling start with the name of step through useEffect.

Is there any way to start the tour without clicking any button?

@lurdharry
Copy link

I had similar issue but was able to fix it, Here is my solution

const { currentStepNumber } = useCopilot()
  const isMounted = useIsMounted();
  
useEffect(() => {
    const timeout = setTimeout(() => {
      if (isMounted.current && currentStepNumber === 0) {
        start();
      }
    }, TIMEOUT);
    return () => clearTimeout(timeout);
  }, [currentStepNumber, isMounted,  start]);
  

you can search for IsMounted Hook, but I can help you with it if you are unable to find any.

@Saigronas
Copy link

The fix @lurdharry mentions does not work here.

Any update would be greatly appreciated.

@lurdharry
Copy link

@Saigronas try replacing the useEffect hook with useFocusEffect hook from react navigation.

It was working well when I used useEffect but it stopped working at some point may be due to metro bundler cache issue, but since I changed to useFocusEffect , it has been working perfectly even in production.
And also, you don’t need the userIsMounted hook when using useFocusEffect.

@Saigronas
Copy link

Even by using useFocusEffect, (which i already used for another reason), i cannot get the tour to start on its own or by navigating to the screen.

However, when pressing "ctrl+s" and thereby refreshing the app, the tour starts.
This was also the case with using useEffect

@tanmoygo
Copy link

tanmoygo commented Jul 5, 2023

@Saigronas did you get any solution?

@shreya-kalra-vs
Copy link

any update on the issue?

@work4m
Copy link

work4m commented Aug 29, 2023

I encountered an issue where the code wasn't functioning within the useEffect or useFocusEffect hooks. However, I managed to identify the solution that works perfectly for my use case in the code. To implement this, make sure to place the following code snippet within the top-level container:

<View onLayout={() => start()}>

@NewDimix
Copy link

@Saigronas did you get any solution?

@carl0shd
Copy link

carl0shd commented May 7, 2024

same problem here, the start() doesn't work if it is called inside of a useEffect

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

8 participants