0
render() {
   console.log("render")
         return (
      <div className="cont">

{() => {
  console.log("works!")

if(condition)
return(<div className="btnnav" onClick={(event) => this.change(event)} 
></div>)

}}

I try to put a condition inside the return but appear this error enter image description here

Israel Martins
  • 188
  • 1
  • 10
  • you are using iife in a wrong way, also you can avoid that and directly use ternary operator for conditional rendering. – Mayank Shukla Mar 21 '18 at 14:05

2 Answers2

2

You can simplify this:

render() {
  return (
      <div className="cont">
      { condition && <div className="btnnav" onClick={(event) => this.change(event)}></div> }
      </div>
  );
}
Faly
  • 12,802
  • 1
  • 18
  • 35
1

As the error is trying to tell you, you're telling React to print a function, which doesn't really make sense.

You need to call the function:

{(() => { ... return ...}())}
SLaks
  • 837,282
  • 173
  • 1,862
  • 1,933