React Dev tools show my Component as Unknown

后端 未结 4 1822
半阙折子戏
半阙折子戏 2021-01-31 16:14

I have the following simple component:

import React from \'react\'
import \'../css.scss\'

export default (props) => {
  let activeClass = props.out ? \'is-ac         


        
4条回答
  •  后悔当初
    2021-01-31 16:28

    I realise the original question has been correctly answered already, but I just wanted to note a very similar issue you may encounter if using React.memo() or similar function. Consider the following code:

    const MyComponent = React.memo(props => 
    Hello
    ) export default MyComponent

    The component will still display as Anonymous in devtools and certain React error messages (e.g. prop-types validation).

    Ensuring that the Component is defined before trying to memoise it resolves this issue, e.g:

    const MyComponent = props => 
    Hello
    export default React.memo(MyComponent)

提交回复
热议问题