我正在尝试使用react-native来学习redux,所以我做了一些例子,但是对于每个人来说,即使它们不同,我也会遇到同样的错误。
我的代码是这样的:
index.js :
import { AppRegistry } from 'react-native';
import App from './src/app';
AppRegistry.registerComponent('reduxExample', () => App);
的src / app.js :
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import { Store } from './store';
import Home from './components/home';
export default props => (
<Provider store={Store}>
<Home />
</Provider>
)
的src /组件/ home.js :
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { View, Text, Button, Input } from 'react-native';
class Home extends Component {
render() {
const { newValue } = this.props;
return (
<View>
<Input type='text' />
<Button>
Click me!
</Button>
<Text>{newValue}</Text>
</View>
);
}
}
const mapStateToProps = store => ({
newValue: store.clickState.newValue
});
export default connect(mapStateToProps)(Home)
SRC /存储/ index.js :
import { createStore } from 'redux';
import { Reducers } from '../reducers';
export const Store = createStore(Reducers);
其他我认为他们不必处理问题,但如果我需要放置代码。