使用 redux 打开菜单
Open menu using redux
我正在尝试通过调度操作来打开菜单,使用 react-navigation
:
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Image, TouchableHighlight, View } from 'react-native';
import { navigate } from './actions.js'
class HeaderLeft extends Component {
constructor(props) {
super(props);
this.showMenu = this.showMenu.bind(this);
}
showMenu() {
this.props.dispatch(navigate('DRAWER_OPEN'));
}
render() {
return (
<View>
<TouchableHighlight onPress={this.showMenu()}>
<Image source={require('../images/home-icon.png')} style={{width: 30, height: 30}} />
</TouchableHighlight>
</View>
);
}
}
export default connect()(HeaderLeft);
我正在使用 redux,我收到未定义的错误 cannot read property 'navigate
我正在导入下面的操作文件:
import { NavigationActions } from 'react-navigation';
export const navigate = (routeName, params, action) =>
NavigationActions.navigate({ routeName, params, action });
actions
未定义,因为默认情况下您不会在文件 action.js
中导出任何内容。正确的导入应该是
import { navigate } from './actions.js';
我正在尝试通过调度操作来打开菜单,使用 react-navigation
:
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Image, TouchableHighlight, View } from 'react-native';
import { navigate } from './actions.js'
class HeaderLeft extends Component {
constructor(props) {
super(props);
this.showMenu = this.showMenu.bind(this);
}
showMenu() {
this.props.dispatch(navigate('DRAWER_OPEN'));
}
render() {
return (
<View>
<TouchableHighlight onPress={this.showMenu()}>
<Image source={require('../images/home-icon.png')} style={{width: 30, height: 30}} />
</TouchableHighlight>
</View>
);
}
}
export default connect()(HeaderLeft);
我正在使用 redux,我收到未定义的错误 cannot read property 'navigate
我正在导入下面的操作文件:
import { NavigationActions } from 'react-navigation';
export const navigate = (routeName, params, action) =>
NavigationActions.navigate({ routeName, params, action });
actions
未定义,因为默认情况下您不会在文件 action.js
中导出任何内容。正确的导入应该是
import { navigate } from './actions.js';