简体   繁体   English

无法将react组件作为属性传递给另一个组件

[英]Unable to pass react component as attribute to another component

I am trying to set a React component as an attribute to another react component like this (I'm using material ui): 我正在尝试将React组件设置为另一个React组件的属性,如下所示(我正在使用材料ui):

<Tabs>
   <Tab icon={<ActionFlightTakeoff />} />
</Tabs>

But in the browser inspect shows me this: 但是在浏览器中,检查显示给我:

<div icon="[object Object]" tabindex="1" style="did-flip:true;display:table-cell;cursor:pointer;text-align:center;vertical-align:middle;height:48px;color:rgba(255,255,255,0.6);outline:none;font-size:14px;font-weight:500;white-space:initial;font-family:Roboto, sans-serif;box-sizing:border-box;width:33.333333333333336%;" data-reactid=".0.1.0.$1/=11"></div>

Basically, the react component is getting generated as [object Object] , without the icons being generated 基本上,react组件将作为[object Object]生成,而不会生成图标
What could I be doing wrong? 我可能做错了什么?

Here is the complete file: 这是完整的文件:

import React, { Component, PropTypes } from 'react';
import Tabs from 'material-ui/lib/tabs/tabs';
import Tab from 'material-ui/lib/tabs/tab';
import FontIcon from 'material-ui/lib/font-icon';
import ActionFlightTakeoff from 'material-ui/lib/svg-icons/action/flight-takeoff';

export default React.createClass({

  styles: {
    paper: {
      height: 100,
      margin: 10,
      padding: 10,
      textAlign: 'center'
    }
  },

  render: function() {
    return (

            <Tabs>
              <Tab icon={<FontIcon className="muidocs-icon-action-home" />} />
              <Tab icon={<ActionFlightTakeoff />} />
              <Tab icon={<FontIcon className="material-icons">favorite</FontIcon>} />
            </Tabs>
    );
  }

});

I've tried your code and for me works fine. 我已经尝试过您的代码,并且对我来说效果很好。 I'm using React version 15.0.2. 我正在使用React版本15.0.2。

I'm not sure, but I think the way you are trying it, it's the right one. 我不确定,但是我认为您尝试的方式是正确的。 You want to put the Component inside the "icon" prop. 您想将组件放置在“ icon”道具内。

I've looked for it in the docs, and it's waiting for a FontIcon or a SvgIcon. 我已经在文档中寻找它,并且正在等待FontIcon或SvgIcon。 Thus, the problem is not the Prop. 因此,问题不在于支柱。

Material UI Tab's 材质UI选项卡的

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

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