React/Redux를 처음 사용하고 프로그래밍하는 것을 처음으로 접했습니다. 아래는 3 파일 사이에 내 코드입니다. 내 React-Router를 감싸는 공급자에게 저장소를 전달합니다. 문제는 1)에서, getTweets을 실행하고 작업을 제대로 가져올 수 있습니다. testing()이 문제가 없기 때문입니다. 그러나 fetchAllTweets의 디버거는 결코 동작하지 않습니다. 재향 군인 여러분, 내 문제가 무엇인지 알려주실 수 있습니까?mapDispatchToProps 메소드가 액션을 디스패치하는 방법
1) 관련 컨테이너 코드 :
import {connect} from 'react-redux';
import Feed from './feed';
import {fetchAllTweets, testing} from '../../actions/tweet_actions';
import thunk from 'redux-thunk';
const mapDispatchToProps = (dispatch) => ({
getTweets:() => {
testing();
return dispatch(fetchAllTweets);
}
});
const FeedContainer = connect(mapStateToProps, mapDispatchToProps)(Feed);
export default FeedContainer;
2) 관련 활동 코드
import * as APIUtil from '../util/tweet_api_util';
import Constants from '../constants/constants';
import thunk from 'redux-thunk';
export const fetchAllTweets =() => dispatch => {
debugger;
console.log('fetch all tweets action');
APIUtil.fetchAllTweets()
.then(tweets => dispatch(receiveTweets(tweets))),
err => dispatch(receiveErrors(err.responseJSON))
};
export const testing =() => {
debugger;
console.log("worked");
}
3) 스토어 당신은 bindActionCreators을 시도하고 그것을 사용할 수도 있습니다
import { createStore, applyMiddleware } from 'redux';
import RootReducer from '../reducers/root_reducer';
import thunk from 'redux-thunk';
const configureStore = (preloadedState = {}) => (
createStore(
RootReducer,
preloadedState,
applyMiddleware(thunk)
)
)
export default configureStore;
감사입니까? – stckoverflowaccnt12
좋은 연습입니다. 이렇게하면 컨테이너 내부에 redux 로직을 유지하는 데 도움이됩니다. 즉, 구성 요소가 더 깨끗해지며 소품의 액션 만 호출하면됩니다. –