【问题标题】:how to create shopping cart notification in react for sort time?如何在排序时间反应中创建购物车通知?
【发布时间】:2023-02-07 11:51:07
【问题描述】:

如何在我点击添加到购物车按钮时创建购物车通知(就像在亚马逊中,当你点击添加到购物车时)以响应排序时间?

我在用

const change = useSelecter(state => state.cart.change) 使用Syour texttate(()=> { 如果(改变){ } ` },[改变])

当我点击添加到购物车时它会触发,但在触发后我希望通知在 1 秒内消失

enter image description here

【问题讨论】:

    标签: reactjs redux-toolkit


    【解决方案1】:

    我会使用 https://www.npmjs.com/package/react-toastify 或使用 setTimeout() 创建回调函数,例如

      // On componentDidMount set the timer
      useEffect(() => {
        const timeId = setTimeout(() => {
          // After 3 seconds set the show value to false
          setShow(false)
        }, 3000)
    

    PS:该代码取自How to disappear alert after 5 seconds in React JS?,以节省手动编写的时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-29
      • 2014-02-27
      • 2020-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多