템플릿 컴포넌트가 많이 있습니다. 사용되는 방식이 서로 비슷합니다. 페이지에 렌더링되기 전에 템플릿 구성 요소가 graphql에 래핑되고 redux에 연결됩니다. 템플릿을 데이터에 연결할 때마다 새 컨테이너를 만들지 않도록 내 템플릿을 감싸는 HOC를 만들고 싶습니다. 내 gqlList HOC 여기HOC을 사용하여 graphql과 redux로 컴포넌트를 래핑 할 수 있습니까?
import React from 'react'
import { AdminTemplate, AppointmentsListTemplate } from 'components'
import { gqlList } from 'containers'
import {qyListAppointments} from 'services/gqlQueries/Appointments'
const AppointmentsListTemplateWrapped = gqlList(AppointmentsListTemplate, qyListAppointments)
const AdminAppointmentsPage = (props) => {
return (
<AdminTemplate>
<AppointmentsListTemplateWrapped />
</AdminTemplate>
)
}
export default AdminAppointmentsPage
을 그리고 : 여기
내가 gqlList HOC으로 AppointmentsListTemplate 템플릿을 포장하려고 내 페이지의 구성 요소는 다음과 같습니다 과 같이import React, {Component} from 'react'
import { graphql } from 'react-apollo'
import { connect } from 'react-redux'
import { saveQueryVars } from 'store/helper/actions'
const gqlList = (WrappedComponent, gqlQuery) => {
const GQL = graphql(gqlQuery)(WrappedComponent)
return connect(null, {
saveQueryVars,
})(GQL)
}
export default gqlList
하지만 graphql 커넥터 부분에서 다음과 같은 오류가 발생합니다.
Uncaught TypeError: Cannot read property 'displayName' of undefined at getDisplayName (react-apollo.browser.umd.js:250) at wrapWithApolloComponent (react-apollo.browser.umd.js:266) at new eval (gqlList.js:22) at eval (createClassProxy.js:95) at instantiate (createClassProxy.js:103) at Unknown (eval at proxyClass (createClassProxy.js:NaN), :4:17) at eval (ReactCompositeComponent.js:303) at measureLifeCyclePerf (ReactCompositeComponent.js:73) at ReactCompositeComponentWrapper._constructComponentWithoutOwner
내가 뭘 잘못하고 있니?
'AppointmentsListTemplate'은 사용자가 hoc에 전달할 때 정의되지 않은 것처럼 보입니다. '{AppointmentsListTemplate}'의 'components''에서 뭔가 나오는지 확인할 수 있습니까? –
네, 올 수 있습니다. 나는이 방법을 렌더링 할 때 , 그것을 작동 : 'CONST AdminAppointmentsPage = (소품) => { 리턴 ( AdminTemplate> ) }' –