React native React导航与Redux-抽屉关闭错误
我正在对redux使用react导航,在redux集成之后,我在抽屉关闭时遇到了一些错误 我称之为“打开”的文件:React native React导航与Redux-抽屉关闭错误,react-native,redux,react-navigation,React Native,Redux,React Navigation,我正在对redux使用react导航,在redux集成之后,我在抽屉关闭时遇到了一些错误 我称之为“打开”的文件: import React from "react"; import PropTypes from "prop-types"; import { TouchableOpacity } from "react-native"; import { createStructuredSelector } from 'reselect'; import { connect } from 'r
import React from "react";
import PropTypes from "prop-types";
import { TouchableOpacity } from "react-native";
import { createStructuredSelector } from 'reselect';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import Icon from "react-native-vector-icons/dist/MaterialIcons";
import { DrawerBurger } from "../common/styles";
import { navigate } from "../store/actions";
const drawerButton = (props) => (
<DrawerBurger>
<TouchableOpacity
onPress={() => props.navigate("DrawerOpen")}
>
<Icon name="menu" size={30} color="white" />
</TouchableOpacity>
</DrawerBurger>
);
drawerButton.propTypes = {
navigate: PropTypes.func.isRequired,
};
const mapStateToProps = createStructuredSelector({});
const mapDispatchToProps = dispatch => (
(
bindActionCreators({
navigate,
}, dispatch)
)
);
export default connect(mapStateToProps, mapDispatchToProps)(drawerButton);
我的环境是:
- 反应导航:1.5.11
- 反应本机:0.53.0
- react导航redux帮助程序:1.0.5
- 反应还原:5.0.7
- redux:3.7.2
- 节点:8.9.4
- 净现值:5.6.0
感谢您的帮助。根据redux集成,您似乎错过了一步 您需要从反应导航添加
addNavigationHelpers
用法
import {addNavigationHelpers} from 'react-navigation';
<AppNavigator navigation={addNavigationHelpers({
dispatch,
state: nav,
addListener,
})} />
从“反应导航”导入{addNavigationHelpers};
我可以看看你的减速机初始化文件吗,还有你调用DrawerView.js中的DrawerView.js中的Error的位置,所以很高兴看到it@PritishVaidya我在问题中添加了相关文件。谢谢。你也可以分享你的操作
文件吗?@PritishVaidya在问题中添加了相关操作。我阅读了文档,但当我查看示例时,他们没有使用addNavigationHelpers。不管怎样,它现在正在工作,非常感谢。
import React from "react";
import PropTypes from "prop-types";
import { TouchableOpacity } from "react-native";
import { createStructuredSelector } from 'reselect';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import Icon from "react-native-vector-icons/dist/MaterialIcons";
import { DrawerBurger } from "../common/styles";
import { navigate } from "../store/actions";
const drawerButton = (props) => (
<DrawerBurger>
<TouchableOpacity
onPress={() => props.navigate("DrawerOpen")}
>
<Icon name="menu" size={30} color="white" />
</TouchableOpacity>
</DrawerBurger>
);
drawerButton.propTypes = {
navigate: PropTypes.func.isRequired,
};
const mapStateToProps = createStructuredSelector({});
const mapDispatchToProps = dispatch => (
(
bindActionCreators({
navigate,
}, dispatch)
)
);
export default connect(mapStateToProps, mapDispatchToProps)(drawerButton);
...
class Dashboard extends Component {
static navigationOptions = () => ({
headerTitle: <Header dashboard />,
headerStyle: { backgroundColor: '#2c4e0f' },
headerLeft: <DrawerButton />,
});
...
import { NavigationActions } from "react-navigation";
import {...} from './constants';
...
export const navigate = routeName => NavigationActions.navigate({ routeName });
import {addNavigationHelpers} from 'react-navigation';
<AppNavigator navigation={addNavigationHelpers({
dispatch,
state: nav,
addListener,
})} />