0
srcが提供されていない場合、名前の最初の文字を子としてレンダリングするためのラッパーを作りたいと思っています。問題は、ListItemのleftAvatar小道具を置くと、同じ行にレンダリングされないということです。Avatar ListItem上のsrcまたはchildren
import React from 'react';
import Avatar from 'material-ui/Avatar';
export default function UserAvatar(props) {
const {
size,
src,
name
} = props;
return (
<Avatar
size={size || 40}
src={src || null}
>
{src ? null : name.charAt(0)}
</Avatar>
);
}
UserAvatar.propTypes = {
name: React.PropTypes.string.isRequired,
size: React.PropTypes.number,
src: React.PropTypes.string
};
私はそれをレンダリングしたい:
import UserAvatar from './UserAvatar';
...
<ListItem
primaryText={post.title}
secondaryText={post.user.firstName}
leftAvatar={<UserAvatar
src={post.user.avatar}
name={post.user.firstName}
/>
}
leftAvatar={post.user.avatar}
/>
がここに(私は私のラッパーを使用いけないとき)レンダリング予想レンダリング
だ
ありがとうございました –