inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

리액트로 나만의 블로그 만들기(MERN Stack)

(24) Header(5) - AppNavBar Auth

redux-promise 적용에 대하여 질문올립니다

347

k0502s

작성한 질문수 20

0

안녕하세요. 제가 강의의 내용을 응용해보고 싶어서 redux-promise을 통해 적용해보고자 했는데 

간단한 실험을 해보니

TypeError: dispatch(...).then is not a function

계속 위의 에러가 뜨면서 안되네요..

일단 아래와 같이 redux-promise을 적용해보았습니다.

뭐가 문제일까용...

import { createStorecomposeapplyMiddleware } from 'redux';
import createSagaMiddleware from 'redux-saga';
import { createBrowserHistory } from 'history';
import { routerMiddleware } from 'connected-react-router';
import promiseMiddleware from 'redux-promise';


import createRootReducer from './redux/reducers/index';
import rootSaga from './redux/sagas'

export const history = createBrowserHistory();

const sagaMiddleware = createSagaMiddleware();

const initialState = {} // state 초기값

const middlewares = [sagaMiddlewarerouterMiddleware(history), promiseMiddleware]
const devtools = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;

const composeEnhancer =
  process.env.NODE_ENV === "production" ? compose : devtools || compose;

  //createStore안에 있는 3개를 합쳐 store을 만들어주는 것
const store = createStore(
  createRootReducer(history),
  initialState,
  composeEnhancer(applyMiddleware(...middlewares))
);

//saga 미들웨어 작동하기 위한 것
sagaMiddleware.run(rootSaga);
////////////////////////
아래는 redux-promise가 되는지 실험해본 코드입니다.
AppNavbar의 로그인 전송버튼입니다.
export default store;
const onSubmit = (e=> {
    e.preventDefault();
    const { emailpassword } = form;
    const user = { emailpassword };
    console.log(user);
    dispatch({
      type: LOGIN_REQUEST,
      payload: user,
    }).then(() => {
      console.log('Test');
    });
 };

redux mongodb express react nodejs bootstrap

답변 2

0

k0502s

그렇군요. 감사합니다!

0

싸플

redux-promise는 사용해보지 않아 잘은 모르겠지만...

일단 해당 사용법을 보니 saga 처럼 dispatch 하는 건 아닌 것 같습니다. 

https://github.com/redux-utilities/redux-actions

redux promise는 redux action을 사용한다고 하니 참고해보시기 바랍니다. ^^;

npm run dev-watch 오류

0

76

1

npm i react-redex redux-saga react-router-dom connected-react-router bootstrap reactstrap dotenv 명령어 설치하면 에러날까요?

0

439

1

mongodb 자세히 알고 싶습니다

0

264

1

강의 듣으면서...포스트 맨도 안됩니다

0

246

1

혹시 gatsby 생성하는 명령어 하는지 알고 싶습니다

0

274

1

webpack 설정 문제입니다.

0

309

1

Category관련 질문

0

231

1

https://www.ssaple.net/ 블로그 접속이 되질 않아요.

0

311

1

리액트 버전 오류 나시는 분들 참고

0

480

1

react 18버전에서의 connected-react-router 가 설치가안됩니다

0

1068

1

jwt.sign() 에서의 질문입니다.

0

205

1

ssaple.net 접속이 안됩니다.

0

367

1

Media(Video) 파일 첨부관련 질문

0

296

1

페이지 Link를 이용한 페이지 이동이 안됩니다

0

337

1

webpack.config.js 설정

0

832

1

몽고db 사이트가 많이 바뀌어서

0

343

1

선생님 req에 아무것도 안들어오는데 혹시 뭐가문제일까요 ?

0

300

1

안녕하세요 강의 잘 보고 있습니다 질문 하나 있는데요 ..

0

1585

1

그대로 따라하였고 하루종일 reboot하는데 되지않습니다..

0

211

1

Encountered two children with the same key 에러..

0

864

1

강사님 redux에러 질문이요

1

243

2

선생님 왜 저는 백날해도 collapse 내용이 link아래로 갈까요?

0

349

2

postDetail scss 문제

0

233

3

강사님 포스트 디테일 부분을 똑같이 작성하였는데 이런 오류가 나서 도저히 방법을 모르겠습니다 ㅠㅠ

0

210

1