react-native - 如何在 React Native 中从功能组件调用函数?
问题描述
从 Class 组件调用函数很容易。但是如何从另一个类或功能组件中的功能组件调用函数呢?
任何解决方案。我在stackOverflow上搜索了很多教程,但仍然没有解决方案。请提供任何解决方案。
抽屉设置.dart
import * as React from 'react';
import { Button, View, Text, TouchableOpacity } from 'react-native';
import {
createDrawerNavigator, DrawerContentScrollView,
DrawerItemList,
DrawerItem,
} from '@react-navigation/drawer';
import { NavigationContainer } from '@react-navigation/native';
import Resources from '../DrawerScreens/Resources';
import Themes from '../DrawerScreens/Themes';
import AboutUs from '../DrawerScreens/AboutUs';
import CustomSidebarMenu from './CustomSidebarMenu';
import Login from '../Validation/Login';
import AsyncStorage from '@react-native-async-storage/async-storage';
const Drawer = createDrawerNavigator();
export default function DrawerSetting({route, navigation }) {
console.log("email is = " + password);
add = () =>{
console.log("Addition called");
}
AsyncStorage.getItem("userId").then((val) => {
console.log("Drawer valuse are=" + val);
});
return (
<NavigationContainer independent={true} >
<Drawer.Navigator initialRouteName="Resources" drawerContent={(props) => <CustomSidebarMenu {...props} />}
>
<Drawer.Screen name="Resources" component={Resources}
options={{ drawerLabelStyle: { fontSize: 16, color: 'black', fontWeight: 'bold', } }}
/>
<Drawer.Screen name="Themes" component={Themes}
options={{ drawerLabelStyle: { fontSize: 16, color: 'black', fontWeight: 'bold', } }}
/>
<Drawer.Screen name="About Us" component={AboutUs}
options={{ drawerLabelStyle: { fontSize: 16, color: 'black', fontWeight: 'bold', } }}
/>
</Drawer.Navigator>
</NavigationContainer>
);
}
如何从另一个类或功能组件中的 DrawerSetting() 组件调用 -> add() 函数?
解决方案
推荐阅读
- node.js - Mocha 变量已初始化,但使用时为空
- c++ - 为什么 B 类中的 f2 被 D 类中的 f2 覆盖
- spring-cloud-contract - 定义合同 DSL 以将 JSON 元素的数量从请求发送到响应
- c# - 如何在 ItemsControl 中实现 DependencyProperty
- javascript - 将自定义数据传递给 Fancybox 实例
- r - 在r中按不同顺序按多列对关联规则进行排序
- python - 使用翻译成python的InterX函数的模块错误
- sql - sqlite 查询适用于加法而不是除法
- javascript - 使用响应类型“cors”在缓存中创建响应
- javascript - 如何将 blob 存储在另一个位置,即。/uploads/audio/currenttime.wav?