Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
873 views
in Technique[技术] by (71.8m points)

reactjs - React Material UI icon passed in props --> to jsx (Typescript)

I use an icon from the library of material UI in React environment. I pass this icon as a property to child react element and I want to render it inside this child.

So if in general you just need to:

import DeleteIcon from '@material-ui/icons/Delete';

...

render(
       <DeleteIcon/>
)

now I got it as a property within the child element, and this is my code for the child:

export const InteractiveListItem: React.FC<{ Icon?: OverridableComponent<SvgIconTypeMap<{}, "svg">> }> = (props) => {

    return (
        {props.Icon}  ------> not rendered!
    )

How do I "convert" this ovverrideableComponent into acceptable ReactElement?

question from:https://stackoverflow.com/questions/65902214/react-material-ui-icon-passed-in-props-to-jsx-typescript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Make sure you pass props in the right way: Icon={<DeleteIcon />}, as you specified this in your InteractiveListItem component.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...