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
  • 198
  • 1
  • 11
  • 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
  • 13,291
  • 2
  • 19
  • 37
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
  • 868,454
  • 176
  • 1,908
  • 1,964