首页 > 解决方案 > 从 Redux 传递 props

问题描述

如何在不从父组件传递 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)

标签: javascriptreactjsreact-redux

解决方案


道具作为功能组件的参数传递

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

或者您可以使用解构语法

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

推荐阅读