-
Notifications
You must be signed in to change notification settings - Fork 527
Expand file tree
/
Copy pathwithTour.js
More file actions
34 lines (29 loc) · 846 Bytes
/
withTour.js
File metadata and controls
34 lines (29 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import React, { useCallback } from 'react'
import { STATUS } from 'react-joyride'
import { useTours } from '../../contexts/tours-context'
/**
* @param {React.ComponentType<any>} WrappedComponent
* @returns {React.ComponentType<any>}
*/
const withTour = WrappedComponent => {
/**
* @param {Object} props
*/
const WithTour = (props) => {
const { disableTours } = useTours()
const handleJoyrideCallback = useCallback(
/**
* @param {import('react-joyride').CallBackProps} data
*/
(data) => {
const { action, status } = data
if (action === 'close' || status === STATUS.FINISHED) {
disableTours()
}
}, [disableTours]
)
return <WrappedComponent handleJoyrideCallback={handleJoyrideCallback} {...props} />
}
return WithTour
}
export default withTour