简体   繁体   English

警告:道具类型失败:提供给“ DropdownItem”的道具“ as”无效

[英]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.

相关问题 反应警告:失败的道具类型:提供的“对象”类型的无效道具 - React Warning: Failed prop type: Invalid prop of type `Object` supplied 警告:道具类型失败:提供给“路线”的道具属性无效。 在途中 - Warning: Failed prop type: Invalid prop `component` supplied to `Route`. in Route 警告:道具类型失败:提供给 `ForwardRef(Slider)` 的道具 `value` 无效 - Warning: Failed prop type: Invalid prop `value` supplied to `ForwardRef(Slider)` 警告:失败的道具类型:提供给“图像”的无效道具&#39;源&#39; - Warning: Failed prop type: Invalid prop 'source' supplied to 'Image' 警告:道具类型失败:提供给“Form(AddComment)”的道具“initialValues”无效 - Warning: Failed prop type: Invalid prop `initialValues` supplied to `Form(AddComment)` 警告:道具类型失败:提供给“NavLink”的道具“标签”无效 - Warning: Failed prop type: Invalid prop `tag` supplied to `NavLink` 失败的道具类型:提供给“重定向”的无效道具“到” - Failed prop type: Invalid prop `to` supplied to `Redirect` 提供给“DropdownItem”的无效道具“children”需要一个 ReactNode - Invalid prop `children` supplied to `DropdownItem` expected a ReactNode 警告:道具类型失败:提供给“路由”的道具“组件”无效:道具不是路由中的有效 React 组件 - Warning: Failed prop type: Invalid prop 'component' supplied to 'Route': the prop is not a valid React component in Route 警告:propType失败:提供给“ LaptopHandling”的类型为“ function”的无效prop`swimmingSnapshot`, - Warning: Failed propType: Invalid prop `swimmingSnapshot` of type `function` supplied to `LaptopHandling`,
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM