【问题标题】:How to call function inside the listener如何在侦听器内部调用函数
【发布时间】:2021-11-26 02:21:33
【问题描述】:

有谁知道如何在监听器中调用函数?我做了这样的事情,对吗?

我的功能:

const toggleShowModal = () => {
    setShowModal(!showModal);
  }

我的听众:

<Tab.Screen
      name='Comments'
      listeners={() => ({
        tabPress: (e) => {
        e.preventDefault();
        setShowModal(true);
        toggleShowModal();
      }
      })}
>

【问题讨论】:

    标签: react-native react-native-navigation


    【解决方案1】:

    是的,我认为您所做的是正确的,但如果您看到代码 showModal 将始终返回 false。你做了什么:

    setShowModal(true) 表示showModal = true 然后 setShowModal(!showModal) in toggleShowModal() 表示!showModal = !true = false

    【讨论】:

      猜你喜欢
      • 2020-01-18
      • 2013-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多