繁体   English   中英

从 Redux 传递道具

[英]Passing props from Redux

如何在不从父组件传递 props 的情况下从 redux 调用 props。

...
<Component name={name}/>
...

我想在这里使用props.something()

const Component = (name) => {


//how to call props here? 
//ex : props.something()

}

export default connect(mapStateToProps,mapDispatchToProps)(Component)

道具作为功能组件的 arguments 传递

const Component = (props) => {
// props.name
}

或者您可以使用解构语法

const Component = ({name}) => {
// name
}

您还可以从道具中解构多个项目。

<MyComponent name={name} title={title} description={description} />
const MyComponent = ({ name, title, description )} => {
  // ...
}

export default MyComponent;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM