これまでは、さまざまなチュートリアルに従ってきました。今回私は物事を最初から作りたいと思っています。今のところ、以下は状態の一部を表示することになっています。後で計算などをして遊びます。それでも私はエラーを取得する:状態ネイティブ/ Reduxエラー
Cannot read property 'count' of undefined
は、だから私はmapStateToPropsを使用して、私が何をしたいのですが最初のステップは、それがthis.props.countとthis.props.stepを表示するために取得することです。私がそれをやったら、もっと複雑なことをするためにそれを修正します。
ここにコンポーネントがあります。下に、githubに書いたコード全体へのリンクがあります。
import React, { Component } from 'react';
import { View, Text } from 'react-native';
import { connect } from 'react-redux';
import { getCounter } from '../actions';
class CounterBoard extends Component {
render() {
return (
<View>
<Text>BELOW SHOULD DISPLAY 0</Text>
<Text>{this.prop.count}</Text>
</View>
);
}
}
const mapStateToProps = (state) => {
return {
count: state.count,
step: state.step
};
};
export default connect(mapStateToProps, { getCounter })(CounterBoard);
https://github.com/wastelandtime/calculator
編集: '小道具' => '小道具' ポインタをありがとうございました。今、私は次のエラーを持っている:
ExceptionsManager.js:63 Objects are not valid as a React child (found: object with keys {count, step}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of `Text`.
あなたはthis.propを持っていて、this.propsである必要があります。 – Hosar
ありがとうございます - それは1つの問題を解決しました。上記の私の更新を参照してください – Wasteland