Fragments in ReactJS(v.16.2.0)

   2021-03-31       8        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

corporate governance
corporate governance..
   2021-02-13       17        Finance
Top 18 Commonly Found Mistakes in Embroidery Digitizer.
Top 18 Commonly Found Mistakes in Embroidery ..
   2019-06-26       115        Arts
Things To Know About Digital Marketing
Things To Know About Digital Marketing..
   2020-12-22       17        Education
Connect Canon Printer To Wi-Fi
Connect Canon Printer To Wi-Fi..
   2019-08-17       96        Services
Here’s What You Should Learn About Storage Beds!
Here’s What You Should Learn About Storage ..
   2021-03-25       12        Fashion
Mild Steel Welding Electrode
Mild Steel Welding Electrode..
   2019-03-18       126        Business
Dryer Vent Cleaning I Cleaning Services
Dryer Vent Cleaning I Cleaning Services..
   2019-05-08       114        Services
A simple design is the key!
A simple design is the key!..
   2019-11-08       38        Internet
 Artificial Intelligence Platform Market
Artificial Intelligence Platform Market ..
   2019-09-06       66        Business
Seo - an Increasing Need of the Digital World
Seo - an Increasing Need of the Digital World..
   2019-07-30       82        Internet
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 : 12424
zero promosi
zero1601@gmail.com
Total Posts : 1754