料青山看我應如是
2021-05-18 13:14:00
我決定重用我認為適用于引入第三方API的新應用程序的組件。有問題的可重用組件正在迭代this.props.data.map(),該組件在我的components/Swipe.js文件中評估為未定義:import React, { Component } from "react";import { View, Animated, PanResponder, Dimensions, LayoutAnimation, UIManager} from "react-native";const SCREEN_WIDTH = Dimensions.get("window").width;const SWIPE_THRESHOLD = 0.25 * SCREEN_WIDTH;const SWIPE_OUT_DURATION = 250;class Swipe extends Component { static defaultProps = { onSwipeRight: () => {}, onSwipeLeft: () => {} }; constructor(props) { super(props); const position = new Animated.ValueXY(); const panResponder = PanResponder.create({ onStartShouldSetPanResponder: (event, gestureState) => true, onPanResponderMove: (event, gestureState) => { position.setValue({ x: gestureState.dx, y: gestureState.dy }); }, onPanResponderRelease: (event, gestureState) => { if (gestureState.dx > SWIPE_THRESHOLD) { this.forceSwipe("right"); } else if (gestureState.dx < -SWIPE_THRESHOLD) { this.forceSwipe("left"); } else { this.resetPosition(); } } }); this.state = { panResponder, position, index: 0 }; } componentWillReceiveProps(nextProps) { if (nextProps.data !== this.props.data) { this.setState({ index: 0 }); } } componentWillUpdate() { UIManager.setLayoutAnimationEnabledExperimental && UIManager.setLayoutAnimationEnabledExperimental(true); LayoutAnimation.spring(); } forceSwipe(direction) { const x = direction === "right" ? SCREEN_WIDTH : -SCREEN_WIDTH; Animated.timing(this.state.position, { toValue: { x, y: 0 }, duration: SWIPE_OUT_DURATION }).start(() => this.onSwipeComplete(direction)); }為什么會這樣,因為我確實payload: data在動作創建者中找到了a :
3 回答

慕哥6287543
TA貢獻1831條經驗 獲得超10個贊
看起來是什么幫助jobs_reducer從以下位置重構了我的文件:
import { FETCH_JOBS } from "../actions/types";
const INITIAL_STATE = {
listing: []
};
export default function(state = INITIAL_STATE, action) {
switch (action.type) {
case FETCH_JOBS:
return action.payload;
default:
return state;
}
}
對此:
export default function(state = INITIAL_STATE, action) {
switch (action.type) {
case FETCH_JOBS:
const { listings } = action.payload;
return { ...state, listing: listings.listing };
default:
return state;
}
}
添加回答
舉報
0/150
提交
取消