How can I suppress “The tag is unrecognized in this browser” warning in React?

前端 未结 4 710
梦如初夏
梦如初夏 2021-02-13 05:58

I\'m using elements with custom tag names in React and getting a wall of these errors. There\'s a GitHub issue on the subject (https://github.com/hyperfuse/react-anime/issues/3

4条回答
  •  孤独总比滥情好
    2021-02-13 06:25

    My solution was to create envelope component which renders

    with desired classes:

    import React, {Component, DetailedHTMLFactory, HTMLAttributes} from "react";
    import classNames from "classnames";
    
    export default class SimpleTagComponent extends Component{
        baseClassName = 'simpleComponent'
    
        render() {
            return React.createElement(
                'div',
                {
                    ...this.props,
                    className: classNames(this.baseClassName, this.props.className),
                },
                this.props.children
            );
        }
    }
    
    type SimplePropTypes = HTMLAttributes
    
    export class MyTag extends SimpleTagComponent {
        baseClassName = 'my'
    }
    

提交回复
热议问题