fri*_*ies 0 reactjs react-props
我在将展开运算符道具传递给组件时遇到问题。它不是返回一个包含值的列表,而是返回一个空列表。
这就是我将 props 传递给组件的方式
const APIKey = "abc";
const url = "def";
const props = { APIKey, url}
return (
<ProfileModal {...props} />
)
Run Code Online (Sandbox Code Playgroud)
但是,它返回一个空列表。
const FunctionName = (anotherPropIhave, props) => {
const { APIKey, url } = props;
}
Run Code Online (Sandbox Code Playgroud)
React 将所有 props 作为 React 功能组件的第一个参数传递。所以这是一个对象。
其他道具的正确获取方式是,...props。
所以:
const FunctionName = ({ anotherPropIhave, ...props }) => {
const { APIKey, url } = props;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
264 次 |
| 最近记录: |