Guided Tour / Joyride Integration to my Website(导游/兜风集成到我的网站)
问题描述
我想为我的 React 应用添加兜风或导游.我想在用户第一次使用它时显示它,并为随后的频繁访问禁用它.我找到了这个库 https://github.com/gilbarbara/react-joyride 但不能不知道如何在同一用户的后续访问中禁用?我可以使用 localstorage 或 cookie 来处理这个问题吗?怎么样?
I want to add a joyride or guided tour for my React App. I want to show it when the users first uses it and disable for subsequent frequent visits. I have found this library https://github.com/gilbarbara/react-joyride but couldn't figure out how to disable on subsequent visits by same user? Can I use localstorage or cookies to deal with this issue? How?
推荐答案
如果你使用的是nextjs或者服务端渲染,这是我的做法:
If you're using nextjs or server-side rendering, here's my approach:
状态已初始化:
runJoyride: (typeof window === 'undefined')? false : window.localStorage.getItem('onboarded') === null,
然后你回电:
handleJoyrideCallback = data => {
const { action, index, status, type } = data;
if ([STATUS.FINISHED, STATUS.SKIPPED].includes(status)) {
this.setState({ runJoyride: false });
window.localStorage.setItem('onboarded', true);
}
};
这篇关于导游/兜风集成到我的网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:导游/兜风集成到我的网站
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Fetch API 如何获取响应体? 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01