Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is react-empty: *?

react-empty

<div data-reactroot>
<!-- react-empty: 3 -->
<!-- react-empty: 26 -->
</div>

What is this node ? Why can it render to a React Component ? How to do like this?

like image 446
Leen Avatar asked Aug 12 '16 17:08

Leen


People also ask

What is React empty?

The React framework offers a shorthand syntax for fragment components that appears as an empty tag: <></> . While it is supported in JSX syntax, it is not part of the HTML standard and thus is not supported natively by browsers. For more information see: Fragments - short syntax.

Is empty in react JS?

To check if a string is empty in React, access its length property and check if it's equal to 0 , e.g. if (str. length === 0) {} . If the string's length is equal to 0 , then the string is empty, otherwise it isn't empty. Copied!

Is null or empty in React?

To check if a variable is null or undefined in React, use the || (or) operator to check if either of the two conditions is met. When used with two boolean values the || operator returns true if either of the conditions evaluate to true . Copied!

How do I return empty in React?

To return nothing from a React component, simply return null . When null is returned from a React component, nothing gets rendered.


1 Answers

This is actually part of React's internal support for things like null:

// A perfectly valid component
() => null

// Also a perfectly valid component
const MyComponent = React.createClass({
  render() {
    if (this.props.hidden) return null;
    return <p>My component implementation</p>;
  }
});
like image 126
Sean Vieira Avatar answered Oct 03 '22 21:10

Sean Vieira