I have the following simple component:
import React from 'react' import '../css.scss' export default (props) => { let activeClass = props.out ? 'is-active' : '' return ( <div className='hamburgerWrapper'> <button className={'hamburger hamburger--htla ' + activeClass}> <span /> </button> </div> ) }
When I look for it in the react dev tools, I see:
Is this because I need to extend React component? Do I need to create this as a variable and do so?
Open the console by either right-clicking and inspecting an element or by opening the toolbar by clicking View > Developer > JavaScript console. The Components tab will show the current React component tree, along with any props, state, or context.
This happens when you export an anonymous function as your component. If you name the function (component) and then export it, it will show up in the React Dev Tools properly.
const MyComponent = (props) => {} export default MyComponent;
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 => <div>Hello</div>) 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 => <div>Hello</div> export default React.memo(MyComponent)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With