O'Reilly logo

Learning Web Development with React and Bootstrap by Mehul Bhatt, Harmeet Singh

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Attribute expressions

If you look at the preceding show/hide example, you can see that we have used attribute expressions to show the message panel and hide it. In React, there is a small change in writing an attribute value, in JavaScript expressions we write attributes in quotes (""), but in React we have to provide a pair of curly braces ({}):

var showhideToggle = this.state.collapse ? (<MessagePanel>):null/>; 

Boolean attributes

Boolean attributes have two values, they can either be true or false, and if we neglect the value in JSX while declaring attributes, then by default it takes the value as true. If we want to have a false attribute value, then we have to use an attribute expression. This scenario can occur regularly when we use HTML form ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required