Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why breaks 'console.log' inside a stateless function expression?

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
)
like image 256
nir.segev Avatar asked Jan 17 '18 13:01

nir.segev


2 Answers

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
);
like image 136
Jan Swart Avatar answered Oct 04 '22 20:10

Jan Swart


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 :)

like image 29
Dzianis Bunchanka Avatar answered Oct 04 '22 22:10

Dzianis Bunchanka