經過大量研究后,每次在訊息框中輸入文本時都會出現此錯誤。
我洗掉了很多代碼 - 所以問題在于文本 Input 和 var state{ ... }
我不知道該怎么做
我計劃將來將資料提交到 SQLite 資料庫,但現在我只是試圖捕獲按鈕按下時的文本輸入 - 我在網上找到了一個腳本,但它不起作用。
const JournalNewEntryScreen = ({navigation}) => {
const messageImage = require('./images/Imatter-icons-13.png');
const homeImage = require('./images/Imatter-icons-14.png');
const settingsImage = require('./images/Imatter-icons-11.png');
const journalHomeImage = require('./images/Imatter-icons-09.png');
const cancelAlert = () =>
Alert.alert(
"Are You Sure?",
"Any content will be deleted and cannot be recovered",
[
{
text: "Cancel",
style: "cancel"
},
{ text: "Yes, I'm Sure",
onPress: () => navigation.navigate("JournalHome") }
]
);
var state = {
message: '',
}
const getValues = () => {
console.log(this.state.message);
}
return (
<>
<StatusBar barStyle='dark-content' />
<SafeAreaView style={homePage.flexContainer}>
<View style={{ flex: 1 }}>
<ScrollView>
<View style={JournalNewEntryPage.container}>
<Image
source={require("./assets/images/cropped-img_1619-1-e1610564001477.png")}
resizeMode="contain"
style={JournalNewEntryPage.image}>
</Image>
<Text style={JournalNewEntryPage.myJournal}>New Journal Entry</Text>
<Text style={JournalNewEntryPage.descriptionText}>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s
</Text>
<Text style={JournalNewEntryPage.messageText}>
Type a message
</Text>
<TextInput
multiline
editable
numberOfLines={4}
style={JournalNewEntryPage.textBox}
onChangeText={(text) => this.setState({ message: text })}
/>
<Text style={JournalNewEntryPage.messageText}>
Attach a file:
</Text>
<Text style={JournalNewEntryPage.upload}>
Add a photo, audio or video file
</Text>
<TouchableOpacity onPress={() => this.getValues()}>
<Text style = {JournalNewEntryPage.journalButton}>
Save Entry
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={cancelAlert}>
<Text style = {JournalNewEntryPage.journalButton}>
Cancel
</Text>
</TouchableOpacity>
<View style = {custom.spacer10}></View>
</View>
</ScrollView>
</View>
{/* <Button title="Reload" onPress={() => navigation.navigate('Home')}/> */}
<View style={homePage.tabBarContainer}>
<View style={homePage.column}>
<TouchableOpacity onPress={hide ? dataButtonHandler : onPress1}>
<Text style={hide ? homePage.button : homePage.codeButton}>{hide ? "Data" : "XXXXXX"}</Text>
</TouchableOpacity>
</View>
<View style={homePage.column}>
<TouchableOpacity onPress={() => navigation.navigate('Home')}>
<Image style={homePage.navImage} source={homeImage}/>
</TouchableOpacity>
</View>
<View style={homePage.column}>
<TouchableOpacity onPress={() => navigation.navigate('JournalHome')}>
<Image style={homePage.navImage} source={journalHomeImage}/>
</TouchableOpacity>
</View>
<View style={homePage.column}>
<TouchableOpacity onPress={messagesButtonHandler}>
<Image style={homePage.navImage} source={messageImage}/>
</TouchableOpacity>
</View>
<View style={homePage.column}>
<TouchableOpacity onPress={() => navigation.navigate('Settings')}>
<Image style={homePage.navImage} source={settingsImage}/>
</TouchableOpacity>
</View>
<View style={homePage.column}>
<TouchableOpacity onPress={hide ? logButtonHandler : onPress3}>
<Text style={hide ? homePage.button : homePage.codeButton}>{hide ? "Logs" : "XXXXXX"}</Text>
</TouchableOpacity>
</View>
</View>
<View style={homePage.tabBarContainerText}>
<View style={homePage.column}>
</View>
<View style={homePage.column}>
<TouchableOpacity onPress={() => navigation.navigate('Home')}>
<Text style={homePage.button}>Home</Text>
</TouchableOpacity>
</View>
<View style={homePage.column}>
<TouchableOpacity onPress={() => navigation.navigate('JournalHome')}>
<Text style={homePage.button}>Journal</Text>
</TouchableOpacity>
</View>
<View style={homePage.column}>
<TouchableOpacity onPress={messagesButtonHandler}>
<Text style={homePage.button}>Messages</Text>
</TouchableOpacity>
</View>
<View style={homePage.column}>
<TouchableOpacity onPress={() => navigation.navigate('Settings')}>
<Text style={homePage.button}>Settings</Text>
</TouchableOpacity>
</View>
<View style={homePage.column}>
</View>
</View>
</SafeAreaView>
</>
);
};
錯誤圖片
uj5u.com熱心網友回復:
您使用的不是基于類的功能組件,因此這不是宣告and的方法,這僅適用于基于類的組件。statessetState
因此,您需要查看此檔案以使用React Hooks https://reactnative.dev/docs/state處理狀態
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/421074.html
標籤:
上一篇:從子組件觸發父組件的方法-反應
