You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 17, 2024. It is now read-only.
Every time a component, that uses the tour context, is re-rendered a new instance of the tour is created.
The new instance is then provided to child components via the context.
If you're trying to trigger the tour automatically using an effect, this will result in the tour being re-created (the tour id will change) every time the provider component is re-rendered.
We are accessing the tour in several components to read the isActive() flag. Maybe this is wrong?
import { useContext } from 'react'
import { ShepherdTourContext } from 'react-shepherd'
const tour = useContext(ShepherdTourContext)
The console output when updating the 'isTourCompleted' flag in the store will be:
***INITIAL RENDER***
Shep sidebar tour tour--34d97abe-ea40-43a2-965e-3fd201f272cd
Shep sidebar tour tour--c1f5a161-9fa3-43e4-a109-bcbb0d8a27a2
Shep sidebar tour tour--c1f5a161-9fa3-43e4-a109-bcbb0d8a27a2
Shep sidebar tour tour--c1f5a161-9fa3-43e4-a109-bcbb0d8a27a2
***SET 'isTourCompleted' FLAG IN STORE***
Shep StartTour props Object { autoStart: true }
Shep StartTour props Object { autoStart: true }
Shep sidebar tour tour--83666ead-d23b-4751-9159-1ef3c1ea0864
Shep sidebar tour tour--83666ead-d23b-4751-9159-1ef3c1ea0864
Shep sidebar tour tour--8a4dce0a-3f9f-40e3-91dc-e23065961e99
Shep sidebar tour tour--8a4dce0a-3f9f-40e3-91dc-e23065961e99
Shep StartTour tour tour--83666ead-d23b-4751-9159-1ef3c1ea0864 true
The StartTour component should not use the old instance of the tour.
(the id should be 'tour--8a4dce0a-3f9f-40e3-91dc-e23065961e99')
When clicking the < p > in Sidebar.js the correct id is used (tour--8a4dce0a-3f9f-40e3-91dc-e23065961e99).
How can this behaviour be prevented?
The text was updated successfully, but these errors were encountered:
YM-KA
changed the title
New instance of the tour created on every render of the provider (#282)
New instance of the tour created on every render of the provider (Relates to #282 ?)
Jul 9, 2021
@YM-KA perhaps setting up a codesandbox would make it easier to debug together? Offhand, I'd think it was correct anytime the component rerenders that you'd get a new tour, so you'd either prevent that via state in your app or perhaps only having the tour on a certain route, etc. Shepherd doesn't have any mechanism for to prevent multiple tours, that all falls on the app itself.
Every time a component, that uses the tour context, is re-rendered a new instance of the tour is created.
The new instance is then provided to child components via the context.
If you're trying to trigger the tour automatically using an effect, this will result in the tour being re-created (the tour id will change) every time the provider component is re-rendered.
We are accessing the tour in several components to read the isActive() flag. Maybe this is wrong?
AppRouter.js - Mounting point
StartTour.js Component - Auto starts the tour
Sidebar.js Component - Has a onClick() to start the tour
The console output when updating the 'isTourCompleted' flag in the store will be:
The StartTour component should not use the old instance of the tour.
(the id should be 'tour--8a4dce0a-3f9f-40e3-91dc-e23065961e99')
When clicking the < p > in Sidebar.js the correct id is used (tour--8a4dce0a-3f9f-40e3-91dc-e23065961e99).
How can this behaviour be prevented?
The text was updated successfully, but these errors were encountered: