강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

br님의 프로필 이미지
br

작성한 질문수

[리뉴얼] React로 NodeBird SNS 만들기

TypeError: Cannot destructure property 'mainPosts' of 오류 어디가 문제일까요...

작성

·

1.5K

0

찾다가 몰라서 오류 질문이요

찾아도 안보입니다 ㅠㅠ

어딘가 빼먹은건가요??

연동이 안된건가요??

코드 이중에 하나인가요?

 

pages폴더 - index.js

import React from 'react';
import { useSelector } from 'react-redux';
import AppLayout from '../components/AppLayout';
import PostCard from '../components/PostCard';
import PostForm from '../components/PostForm';

const Home = () => {
    const {me} = useSelector((state) => state.user);
    const {mainPosts} = useSelector((state) => state.post);

    return (
        <AppLayout>
            {me && <PostForm />}
            {mainPosts.map((post) => 
                <PostCard key={post.id} post={post} />
            )}
        </AppLayout>
        );
};

export default Home;

store 폴더 - configureStore.js

import {createWrapper} from 'next-redux-wrapper';
import {createStore, applyMiddleware, compose} from 'redux';
import {composeWithDevTools} from 'redux-devtools-extension';
import createSagaMiddleware from 'redux-saga';
import reducer from '../reducers';
import rootSaga from '../sagas';

const loggerMiddleware = ({ dispatch, getState }) => (next) => (action) => {
    console.log(action);

    return next(action);
};

const configureStore = () => {
    const sagaMiddleware = createSagaMiddleware();
    const middlewares = [sagaMiddleware, loggerMiddleware];
    const enhancer = process.env.NODE_ENV === 'production'
    ? compose(applyMiddleware(...middlewares))
    : composeWithDevTools(applyMiddleware(...middlewares))

    const store = createStore(reducer, enhancer);
    store.sagaTask = sagaMiddleware.run(rootSaga)
    
    return store;
}

const wrapper = createWrapper(configureStore, {
    debug: process.env.NODE_ENV === 'development',
});

export default wrapper;

package.json

"dependencies": {
    "@ant-design/icons": "^4.7.0",
    "antd": "^4.23.1",
    "axios": "^0.27.2",
    "next": "^12.3.0",
    "next-redux-wrapper": "^6.0.2",
    "prop-types": "^15.8.1",
    "react-redux": "^8.0.2",
    "react-slick": "^0.29.0",
    "redux": "^4.2.0",
    "redux-devtools-extension": "^2.13.9",
    "redux-saga": "^1.2.1",
    "shortid": "^2.2.16",
    "styled-components": "^5.3.5",
    "update": "^0.7.4"
  },
  "devDependencies": {
    "babel-eslint": "^10.1.0",
    "eslint": "^8.23.1",
    "eslint-config-airbnb": "^19.0.4",
    "eslint-plugin-import": "^2.26.0",
    "eslint-plugin-jsx-a11y": "^6.6.1",
    "eslint-plugin-react": "^7.31.8",
    "eslint-plugin-react-hooks": "^4.6.0"
  }
}

강의는 redux-saga 연동하기 부분이에요

답변 1

0

제로초(조현영)님의 프로필 이미지
제로초(조현영)
지식공유자

reducers쪽에 rootReducer랑 postReducer 봐야할 것 같습니다

br님의 프로필 이미지
br
질문자

reducers 폴더 안에

index.js,

post.js,

user.js 이쪽인가요??

제로초(조현영)님의 프로필 이미지
제로초(조현영)
지식공유자

네네 post 리듀서가 제대로 코딩이 안되어있거나 이상하게 연결되어있는듯 하네요

br님의 프로필 이미지
br
질문자

export defalut reducer 안되있었네여..ㅠ

다른곳도 대.소문자 오타 , import 빠뜨린게 껴있어서 .. 겨우 찾았습니다;;

감사합니다 해결했어요

br님의 프로필 이미지
br

작성한 질문수

질문하기