我一直在尝试替换React Native中的视图,但没有成功。每当我尝试<TouchableOpacity onPress={() => {handleChangeMyView();}}>
时,应用程序都会关闭,没有错误:
我做错了什么?我该怎么做?
提前感谢大家。
import React, {
useState
} from 'react';
import {
SafeAreaView,
View,
} from 'react-native';
import MyInitialView from './MyInitialView';
const SiteContainer = () => {
let MyDynamicView = () => {
return (
<View></View>
);
};
const [MyDynamicViewArea, setMyDynamicViewArea] = useState(MyInitialView);
const handleChangeMyView = () => {
setMyDynamicViewArea(MyDynamicView);
};
return (
<SafeAreaView style={styles.siteContainer}>
{MyDynamicViewArea}
<TouchableOpacity onPress={() => {handleChagnStaceMyView();}}>
<View>
<FontAwesome name="quote-left"></FontAwesome>
</View>
</TouchableOpacity>
</SafeAreaView>
);
};
export default SiteContainer;
我的初始视图:
import React from 'react';
import {
View
} from 'react-native';
export default function MyInitialView() {
return (
<View></View>
);
}
2条答案
按热度按时间9vw9lbht1#
您正在调用错误的函数
<TouchableOpacity onPress={() => {handleChagnStaceMyView();}}>
,请将其更改为<TouchableOpacity onPress={() => {handleChangeMyView();}}>
祝你好运
我想知道你没有得到像
handleChagnStaceMyView is not defined
这样的错误db2dz4w82#
TouchableOpacity的onPress中的函数名称不正确。请更改此名称
至