0
親Browse.jsで
React NativeとReduxの小道具としてアクションを伝えるには?アクションクリエータファイル内
import { usersFetch, onToggleFollow } from '../actions';
class Browse extends Component {
render() {
return (
<ListView
....
renderRow={(user) =>
<UserItem user={user}
onPress={() => this.props.onToggleFollow()}
/>}
/>
);
}
}
export default connect(mapStateToProps, { usersFetch, onToggleFollow })(Browse);
子UserItem.jsで
class UserItem extends Component {
render() {
followButton = <Button title='Follow' onPress={() => {
this.props.onToggleFollow();
}}/>;
return (
<View style={styles.cardContainerStyle}>
<View>
{ followButton }
</View>
</View>
);
}
}
:「this.propsを:
export const onToggleFollow =() => {
console.log('onToggleFollow method!');
return (dispatch) => {
dispatch({ type: ON_TOGGLE_SUCCESS });
};
};
私はエラーが語る取得.onToggleFollowは関数ではなく、this.props.onToggleFollowは未定義です。 " UserItem
で
onPress={() => { this.props.onToggleFollow(); }}
: