我正在嘗試存儲(chǔ)一組 Session 對(duì)象。每個(gè) Session 都有一個(gè) Hand 對(duì)象數(shù)組。我正在嘗試建立一個(gè) Redux 商店,但由于某種原因我無法使用 mapStateToProps 訪問我的商店。this.props.* 中的所有選項(xiàng)都與我的 redux 存儲(chǔ)無關(guān)。我的商店應(yīng)該保存一組會(huì)話對(duì)象,我想在一個(gè)簡單的 FlatList 中顯示這些對(duì)象,以便在創(chuàng)建自定義 FlatList 之前了解概念。我展示了一個(gè)我想要使用 State 的例子,但我無法讓它與 Redux 一起工作。我的 {this.props.sessions} 不顯示任何內(nèi)容,我希望它顯示會(huì)話的名稱,就像狀態(tài)按鈕一樣。我嘗試了很多不同的配置,包括翻閱 this.props.* 試圖找到輸出信息的東西。我什至嘗試在 Redux 中使用一個(gè)簡單的“計(jì)數(shù)”變量,看看我是否可以讓它工作,但那也不起作用。這里有潛在的問題嗎?我的應(yīng)用程序運(yùn)行得很好,但是當(dāng)我按下“使用 redux 添加新會(huì)話”按鈕時(shí),它什么也沒做。//*HOME.JSimport React from 'react';import { StyleSheet, View, Text, Button, FlatList} from 'react-native';import { connect } from 'react-redux';import { SessionObject } from './Session';var session = new SessionObject("Session", []);class Home extends React.Component { state = { SessionList : [], SessionCount : 1 } render() { const { navigate } = this.props.navigation; return ( <View style={styles.container}> <View style={styles.container}> <Text>Home Screen!! :)</Text> </View> <View style={styles.style_flex3}> <Button title="Add new Session with State" onPress={() => this.addItem() } /> <FlatList data={this.state.SessionList} renderItem={({item}) => this.SessionComponent(item)} keyExtractor={(item, index) => index.toString()} /> <Text>{this.props.sessions}</Text> <Text>{this.props.Count}</Text> <Button title="Add new Session with Redux!" onPress={() => this.addNewSession() } /> <FlatList data={this.props.sessions} renderItem={({item}) => this.SessionComponent(item)} keyExtractor={(item, index) => index.toString()} /> </View> </View> );我想在我的 Redux 存儲(chǔ)中的 Flatlist 中顯示會(huì)話列表,并且我希望“添加”按鈕在我點(diǎn)擊它時(shí)創(chuàng)建更多會(huì)話。
為什么我不能從 React-Native Redux 中的 mapStateToProps
動(dòng)漫人物
2021-06-11 15:06:47