I'm sure it is just a syntax thing. How can I console.log
inside a stateless function expression?
const Layer = (props) => (
console.log(props); //breaks
)
There's no need to change the structure of the component to use curly braces and adding a return. You can do:
const Layer = (props) => console.log(props) || (
...whatever component does
);
const StatelessComponent = props => {
console.log(props);
return (
<div>{props.whatever}</div>
)
}
Keep in mind that in a functional components there is no render method as is. Your JSX should be written in the return section of a function. That's not the react specific case. That's the behaviour of the arrow function itself. Good luck coding :)
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