Home > Net >  Why can't I print lambda values into my TSX html components?
Why can't I print lambda values into my TSX html components?

Time:02-15

Sorry I'm still learning React and Typescript. Why does this print an empty <h1></h1> instead of <h1>Title</h1> ?

<h1>{() => {return "Title"}}</h1>

Note: I know I could do <h1>{"Title"}</h1> to achieve the desired result, I want to know why can't I do this with a lambda.

CodePudding user response:

You are passing in a function expression without ever calling it, try:

<h1>{(() => {return "Title"})()}</h1>

  • Related