为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

森林海 2021-06-15 17:08:14
我在我的 nextJS 应用程序中使用了一些 HOC 组件来通过getInitialProps. 但是我需要为这些道具使用动态值。在我的索引组件中,我正在调用withServerProps. 是否可以将一些字符串数组传递给它?索引.jsimport 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.jsimport 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} />    }  }
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 128 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信