Four ways to represent conditional expressions:
1, ternary operator, this.props.name?this.props.name: "Hello World";
2, use a function, inside can use if Else statement, and then use a variable to get the return value, directly use the variable on the line;
Getname:function () {
if (this.props.name)
Return This.props.name
Else
Return "Hello World"}
Const A = GetName ();//directly behind {a}
3, is to call this function directly; {this.getname ()}//note here that This.getname () means that the function returned is obtained, and this.getname represents the function called GetName;
4. Using the operator {this.props.name| | Hello world}//says that if This.props.name has a value, take this.props.name, and if not, go to Hello World.
This is a simple all-purpose expression:
function (obj) {
if (obj.props.name)
Return Obj.props.name
else return "World"
}) (this)//the following parenthesis means calling this function and passing in the parameter this
React diff algorithm
In the algorithm, if the nodes are different, end the comparison directly, discard the old nodes, and create a new node. The diff algorithm is performed each time it is rendered, and the old node is not deleted in the algorithm, but it is changed on the old node.
React Study Notes