[英]Warning: Failed prop type: Invalid prop `as` supplied to `DropdownItem`
Here is the code: 这是代码:
import UserPlateFunction from './components/UserPlate';
import {Form, Dimmer, Loader, Message, Header, Dropdown} from 'semantic-ui-react';
import UserPlateFunction from './components/UserPlate';
class Setting extends Component {
render(){
const {members} = this.state;
return(
<Dropdown>
<Dropdown.Menu>
{Object.keys(members).map((key, i) => {
return (
<Dropdown.Item
as={UserPlateFunction(members[key].user.gravatar)}
/>
)
})
} </Dropdown.Menu>
</Dropdown>
)
}
}
The state variables are set in the custom methods(It's too lengthy to add here). 状态变量是在自定义方法中设置的(太长了,无法在此处添加)。 The warning I am getting is 我收到的警告是
Warning: Failed prop type: Invalid prop as
supplied to DropdownItem
. 警告:无法丙类型:无效丙as
供给到DropdownItem
。
./components/UserPlate
import './index.css';
import PropTypes from 'prop-types';
import React from 'react';
let UserPlate = ({gravatar}) => (
<div className="clearfix">
<div className="user-img">
<img src={gravatar} alt='this one'/>
</div>
</div>
);
UserPlate.propTypes = {
gravatar : PropTypes.string.isRequired,
};
function UserPlateFunction(image){
return (<UserPlate gravatar={image}/>)
}
export default UserPlateFunction;
Any idea what's wrong? 知道有什么问题吗? Thanks in advance. 提前致谢。
You need to give a function or the name of a HTML element. 您需要提供函数或HTML元素的名称。 You are returning a React Component. 您正在返回一个React组件。 ( return (<UserPlate gravatar={image}/>)
) ( return (<UserPlate gravatar={image}/>)
)
The correct way would be passing the function bound with your value, so it is executed at render: 正确的方法是传递与您的值绑定的函数,因此它在render处执行:
as={UserPlateFunction.bind(null, members[key].user.gravatar)}
Or, even better, export directly directly UserPlate
and do something similar: 或者,甚至更好的是,直接直接导出UserPlate
并执行类似的操作:
as={UserPlate.bind(null, {
gravatar: members[key].user.gravatar}
)}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.