是否可以使用 HOC 将字符串数组作为参数传递?

我在我的 nextJS 应用程序中使用了一些 HOC 组件来通过getInitialProps. 但是我需要为这些道具使用动态值。


在我的索引组件中,我正在调用withServerProps. 是否可以将一些字符串数组传递给它?


索引.js


import React, { Component } from 'react'

import { withTranslation } from 'i18n'

import withServerProps from 'with-server-props'


class Index extends Component {

  render () {

    return (<div>Some content</div>)

  }

}


export default withServerProps( // <-- How to pass an array with strings?

  withTranslation()(Index) 

)

我需要在这个函数中获取字符串数组:


with-server-props.js


import React, { Component } from 'react'


export default WrappedComponent =>

  class extends Component {

    static async getInitialProps (context) {

      const { query } = context

      return {

        id: query && query.id

        target: PASSED_ARRAY // <-- Need to recieve the array here

      }

    }

    render () {

      return <WrappedComponent {...this.props} />

    }

  }


森林海
浏览 129回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript