Fragments in ReactJS(v.16.2.0)

   2021-03-31       12        Technology
Rating :
The fragment is a first-class component to wrap your child components and HTML elements instead of using any HTML element.

The fragment is a first-class component to wrap your child components and HTML elements instead of using any HTML element.

Normal way of wrapping child component in render method

render(){
  return(
    <div> 
      <Header/>
      <h1> Without Fragment </h1>
    </div>
  );
}

 

For above example, if you will not wrap the child component using <div> tag then you would face syntax error that the JSX element must be rendered in an enclosing tag.To understand this, Let’s think about function call, when we call the function, we can’t return more than once at a time in a function call, and we can return nothing also. So its necessary to wrap child component in an enclosing tag.

To solve above problem, React 16.0 launched a new feature for returning an array of elements from a component’s render method. Instead of wrapping the children in a DOM element, you can put them into an array. Here you can see above example

render() {
  return [
    "

Author Signature :


My name is Sasi kiran working as a software developer in Cronj IT Technologies

100x100
sasi kiran

CronJ is a leading React JS Development Company based in the USA, Bangalore, India, New York, UK developing and offering the best platform for ReactJS development services. We have a professional and ..


Random Articles

Human Lungs (Anatomy) definition and Facts
Human Lungs (Anatomy) definition and Facts..
   2021-04-09       15        Health
How Web Hosting Works?
How Web Hosting Works?..
   2019-08-22       89        Internet
Car Rental from Bhubaneswar to Puri
Car Rental from Bhubaneswar to Puri..
   2019-06-04       92        Business
Gojek Clone App Development | Startupmart
Gojek Clone App Development | Startupmart..
   2020-05-27       32        Business
King Air Ambulance in Dimapur at Low Cost Avail
King Air Ambulance in Dimapur at Low Cost Ava..
   2020-05-23       43        Health
Stress Management all you want to know.
Stress Management all you want to know...
   2020-12-24       21        Health
King Emergency Road Ambulance in Ranchi-The Cost-Effective
King Emergency Road Ambulance in Ranchi-The C..
   2020-10-06       24        Health
Global Rice Seeds Market
Global Rice Seeds Market ..
   2019-08-01       82        Business
Top 10 Commodity Tips Provider and Commodity Market Tips
Top 10 Commodity Tips Provider and Commodity ..
   2019-08-02       128        Finance
ABOUT US

Some quick example text to build on the card title and make up the bulk of the card's content Some quick example text to build on the card title and make up the bulk of the card's content Some quick example text to build on the card title and make up the bulk of the card's content.

TOP AUTHORS
Thomas Shaw
thomasshaw9688@gmail.com
Total Posts : 13123
zero promosi
zero1601@gmail.com
Total Posts : 1939