【问题标题】:NEXTJS pass to hook props and receive redux actionNEXTJS 传递给 hook props 并接收 redux 动作
【发布时间】:2020-07-05 22:35:42
【问题描述】:

我有一个页面,它渲染一个组件并向他们发送一个道具,该组件也接收一个 redux 操作。

export default function Home() {
  return (
    <ComponentReceiver new="yes" />
  )
}


export default function ComponentReceiver({reduxAction}, props) {
  return (
    <h1>{props.new}</h1>
  )
}

这不起作用,props.new 未定义。

【问题讨论】:

    标签: reactjs react-redux next.js


    【解决方案1】:

    您的组件将始终收到道具。 Redux 操作作为道具传递。

    所以你有两个选择。你可以解构你的组件道具:

    export default function ComponentReceiver({reduxAction, new}) {
      return (
        <h1>{new}</h1>
      )
    }
    

    请注意,您必须重命名 new,因为它是保留关键字。

    或者不要破坏,让它只是props,并在你的组件中使用props.new和props.reduxAction。

    【讨论】:

      猜你喜欢
      • 2019-11-15
      • 1970-01-01
      • 1970-01-01
      • 2020-12-04
      • 2019-12-05
      • 1970-01-01
      • 2016-10-13
      • 2016-10-05
      • 2023-01-11
      相关资源
      最近更新 更多