react-native-copilot icon indicating copy to clipboard operation
react-native-copilot copied to clipboard

Calling start() on useEffect does not register/use all steps, only the first one

Open alicja-mruk opened this issue 1 year ago • 10 comments

Current Behavior Calling start on useEffect does not register steps. After clicking "next" it moves to next walkthrouable item, but in the current step always displays the first step content. However, totalSteps displays correct number of steps.

import { useCopilot } from 'react-native-copilot';

const { start }  = useCopilot();

useEffect(() => {
 start()
},[])

[.. in the return function as in /example folder]

Expected behavior/code Steps are registered and "next" press works correctly.

Environment

  • Device: [iPhone 15 Pro Max Simulator]
  • OS: [17.4]
  • react-native-copilot: [3.3.2]
  • react-native: [71.14]
  • react-native-svg: [14.0.0]

Possible Solution

I was able to solve this by adding timeout of 3s in the useEffect. setTimeout(() => { start() }, 3000

Additional context/Screenshots I don't know why it happens, any idea how we can fix it?

alicja-mruk avatar May 29 '24 11:05 alicja-mruk

setTimeout doesn't work for me. I am trying to set false if displayed already.

acelyavul avatar Jun 03 '24 11:06 acelyavul

in my case, it even doesn't trigger. I have to trigger manually by touch event after a second

It seems sometimes useEffect init before all children-in-order finish, did causing problem

this is my fix:

    useEffect(() => {
        // Create a debounced version of the start function
        const debouncedStart = debounce(() => {
            start();
        }, 1000);

        // Call the debounced start function
        debouncedStart();

        // Clean up the debounced function
        return () => {
            debouncedStart.cancel();
        };
    }, [totalStepsNumber]);

depends on "totalStepsNumber" is the key

ngdbao avatar Jun 09 '24 06:06 ngdbao

what is the totalStepsNumber here.give full code

lutakyn avatar Jul 18 '24 01:07 lutakyn

Try my solution:

onLayout={() => { start(); }}

TienNguyenVanDev avatar Aug 24 '24 10:08 TienNguyenVanDev

I am noticing the same issue. It seems like this library isn't maintained much anymore though :(

andrewchester1 avatar Sep 09 '24 00:09 andrewchester1

any solution on how can this be fixed? Creating a debounced version of the start function didn't worked for me

Shivangigupta01 avatar Oct 03 '24 09:10 Shivangigupta01

Maybe instead of one, it should have multiple contexts?

alicja-mruk avatar Oct 03 '24 09:10 alicja-mruk

same issue

Mushthak007 avatar Nov 14 '24 05:11 Mushthak007

in my case, it even doesn't trigger. I have to trigger manually by touch event after a second

It seems sometimes useEffect init before all children-in-order finish, did causing problem

this is my fix:

    useEffect(() => {
        // Create a debounced version of the start function
        const debouncedStart = debounce(() => {
            start();
        }, 1000);

        // Call the debounced start function
        debouncedStart();

        // Clean up the debounced function
        return () => {
            debouncedStart.cancel();
        };
    }, [totalStepsNumber]);

depends on "totalStepsNumber" is the key

Worked for me Thanks! 🙏 ☺️

Hamadahmad000 avatar Nov 20 '24 22:11 Hamadahmad000

Try my solution:

onLayout={() => { start(); }}

This work for me, thanks!

WidgetPMT avatar Aug 22 '25 06:08 WidgetPMT