React + Redux 응용 프로그램을 빌드하려고하는데 Redux Thunk를 사용하고 있습니다.Redux Thunk/Eslint erro
import api from '../api';
export const FETCH_BOOKS = 'FETCH_BOOKS';
export default() => dispatch =>
api
.books()
.perPage(-1)
.then(books =>
dispatch(books => ({
type: FETCH_BOOKS,
books,
}))
)
.catch(error =>
dispatch(e => ({
type: 'ERROR',
error: e,
}))
);
을하지만 yarn run build:production
을 실행할 때 오류 (들)을 얻을 : 내 액션 제작자의
하나는 다음과 같습니다
ERROR in ./scripts/ll-app/actions/fetch-books.js
/Users/joneslloyd/resources/assets/scripts/ll-app/actions/fetch-books.js
9:11 warning 'books' is defined but never used no-unused-vars
11:9 error Expected an assignment or function call and instead saw an expression no-unused-expressions
11:9 error 'books' is already declared in the upper scope no-shadow
17:12 warning 'error' is defined but never used no-unused-vars
19:9 error Expected an assignment or function call and instead saw an expression no-unused-expressions
19:9 error 'error' is already declared in the upper scope
그러나, 내가합니다 (books
배열을 전달 할을 비동기 api 호출에서 반환 된)를 디스 패칭 (익명 함수를 전달하여 전달) 한 다음 해당 감축 기가받을 액션에 books
배열을 포함시킵니다.
여기 뭔가 잘못 되었나요?
내부 참조의 이름을 books
으로 변경하더라도 도움이되지 않습니다.
그것은 내가 여기 ES6에서 뭔가를 내려다 해요 가능합니다 ..하지만 기본적으로합니다 (then
방법의 매개 변수로) API 호출에서 반환 된 books
배열을, 다음의 내부 dispatch
함수에 전달할하려면 즉, 내가 전달하는 익명 함수의 매개 변수로.
이 도움이 될 것이라고 어떤 도움이됩니다. 감사!
당신은 완전히 옳습니다! 고마워요 :) 내부 참조를 'books' /'error'로 이동하면 해결되지만, 사용자의 설명이 완전히 이해됩니다 (저는 ES6를 처음 접했습니다). 건배 –