简体   繁体   English

如何在 React Native 中单击不同页面上的按钮?

[英]How to click a button on a different page in React Native?

If I'm on page 2 and I want to click a button on Homepage, how do I do it?如果我在第 2 页,我想点击主页上的按钮,我该怎么做?

In Javascript, we can just do query selector and DOM manipulation but that functionality doesn't exist in React Native在 Javascript 中,我们可以只进行查询选择器和 DOM 操作,但 React Native 中不存在该功能

You can achieve this by sending and receiving events.您可以通过发送和接收事件来实现这一点。

Using event bus you can fire some events from screen A and receive/catch those events in screen B. While you receive those events, perform the functionality which you want.使用事件总线,您可以从屏幕 A 触发一些事件并在屏幕 B 中接收/捕获这些事件。当您接收这些事件时,执行您想要的功能。

This is the least code correct implementation which you need.这是您需要的最少代码正确实现。

Also, please dont remove the event in componentDidUnmount另外,请不要删除componentDidUnmount中的事件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在本机反应中单击按钮时使用不同的参数调用相同的 api - How to call same api with different params on click of button in react native 如何使按钮单击其他页面上的按钮 - How to make a button click a button on a different page 如何在React Native中单击按钮以打开React Native模式? - How to open a react native modal on button click in react native? 要显示不同的颜色以在按钮上查看,请在react native中单击 - To Show different color to view on button click in react native 单击按钮无法导航到其他组件-React-Native Navigator - Unable to navigate to a different component on button click - React-Native Navigator react native:当我从另一个页面单击按钮时,如何更改视图? - react native: How can I change a view when i click a button from another page? 如何让一个按钮点击 React 中不同组件的另一个按钮 - How to make a button click another button from different components in React 不确定如何通过在 react-native 中单击按钮来呈现此组件 - Not sure how to render this component with click of a button in react-native 如何使用 React native 在按钮单击时更改应用程序中的字体大小 - How to change font size in the app on button click using React native React Native | 单击Button(onPress())后如何渲染标记 - React Native | How to render Markers after click on Button ( onPress() )
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM