我在我的 nextJS 應(yīng)用程序中使用了一些 HOC 組件來通過getInitialProps. 但是我需要為這些道具使用動(dòng)態(tài)值。在我的索引組件中,我正在調(diào)用withServerProps. 是否可以將一些字符串?dāng)?shù)組傳遞給它?索引.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) )我需要在這個(gè)函數(shù)中獲取字符串?dāng)?shù)組: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} /> } }
是否可以使用 HOC 將字符串?dāng)?shù)組作為參數(shù)傳遞?
森林海
2021-06-15 17:08:14