그래서 저는 ApiClient 도우미가있는 반감기 보일러 플레이트를 사용하고 있습니다. 그것은 다음과 같습니다 :이 작업을 수행 할 때, 나는를 얻을비 구성 요소 클래스를 redux 저장소에 연결할 수 있습니까?
@connect(state => ({ jwt: state.auth.jwt }))
export default class ApiClient {
...
을하지만 :
export default class ApiClient {
constructor(req) {
/* eslint-disable no-return-assign */
methods.forEach((method) =>
this[method] = (path, withCredentials, { params, data } = {}) => new Promise((resolve, reject) => {
const request = superagent[method](formatUrl(path))
if (withCredentials) {
console.log('first of all, its true')
console.log(this)
}
if (params) {
request.query(params)
}
if (__SERVER__ && req.get('cookie')) {
request.set('cookie', req.get('cookie'))
}
if (data) {
request.send(data)
}
request.end((err, { body } = {}) => {
return err ? reject(body || err) : resolve(body)
})
}))
/* eslint-enable no-return-assign */
}
/*
* There's a V8 bug where, when using Babel, exporting classes with only
* constructors sometimes fails. Until it's patched, this is a solution to
* "ApiClient is not defined" from issue #14.
* https://github.com/erikras/react-redux-universal-hot-example/issues/14
*
* Relevant Babel bug (but they claim it's V8): https://phabricator.babeljs.io/T2455
*
* Remove it at your own risk.
*/
empty() {}
}
은 내가 보호 엔드 포인트로 헤더를 붙일 수 있도록과 같이, 내 인증이를 연결하려면 오류 : Cannot read property 'store' of undefined
. 무슨 일 이니? 일반 클래스를 redux 상점에 연결할 수없는 이유는 무엇입니까? 업데이트
: 여기 ApiClient 도우미 사용하여 내 로그인 기능이다 :
export function loginAndGetFullInto(email, password) {
return dispatch => {
return dispatch(login(email, password))
.then(() => {
return dispatch(loadUserWithAuth())
})
}
}
내가 loadUserWithAuth
기능으로, 가게, 또는 JWT을 통과 중 어떤 방법이 필요를 ...
*'connect()': ** React 구성 요소 **를 Redux 저장소 *에 연결합니다. 단순히 생성자/속성을 통해 클래스에 저장소에 대한 참조를 전달할 수 없습니까? – CodingIntrigue
@ 코딩 시작 방법? –
다음과 같이 :'var apiClient = new ApiClient (createStore()); .... 생성자 (저장소) {store.getState(); }' – CodingIntrigue