我确实使用standardJS得到了这一行的Parsing error: Unexpected token
linting错误。因此,我的CI失败了。
我不明白这条线怎么了。我该怎么解决这个问题?
export default (App) => {
return class Apollo extends React.Component {
static displayName = 'withApollo(App)' // <--
static async getInitialProps (ctx) {
// ...
}
}
如果这是标准javascript,那么错误是类只能包含函数,而不能包含属性。
正确的语法应该是:
class Apollo extends React.Component {
static async getInitialProps (ctx) {
// ...
}
Apollo.displayName = 'withApollo(App)';
export default (App) => {
return Apollo;
}
如果您正在使用建议的(但尚未实现或批准的(ES7/ES8类属性,那么eslint
可能还不支持它。
如果与原始问题不同,您需要使用App
参数,只需在您想要导出的函数中执行即可:
class Apollo extends React.Component {
static async getInitialProps (ctx) {
// ...
}
export default (App) => {
Apollo.displayName = `withApollo(${App})`;
return Apollo;
}