laravel and react js
I am trying to getting data from laravel route and mapping it in my component when i try small code block under array.map function it works link shown in this image also saying that vision is unresolve variable, but it work and render the data
Now problem is here that when i try some big data under array.map it is making error and not rendering layout problem code is here
<div className="services-pack">
{
sr.map(data =>(
<div className="Sr-item z-depth-1 wow fadeInRight slow">
<div className="icon-wrap">
<div className="S-icon rounded-circle">
<img src="../../../img/fron-end.png" alt="icons fron-end"
className="img-fluid"/>
</div>
</div>
<div className="S-name">
<h3>{data.frontEnd}</h3>
<p>{data.frontEnd-intro}</p>
</div>
</div>
<div className="Sr-item z-depth-1 wow fadeInUp delay-1s slow">
<div className="icon-wrap">
<div className="S-icon rounded-circle">
<img src="../../../img/fron-end.png" alt="icons fron-end"
className="img-fluid"/>
</div>
</div>
<div className="S-name">
<h3>{data.backtEnd}</h3>
<p>{data.backtEnd-intro}</p>
</div>
</div>
<div className="Sr-item z-depth-1 wow fadeInUp delay-1s slow">
<div className="icon-wrap">
<div className="S-icon rounded-circle">
<img src="../../../img/fron-end.png" alt="icons fron-end"
className="img-fluid"/>
</div>
</div>
<div className="S-name">
<h3>Wordpress Website</h3>
<p>Elementor & Visual Composer Dev. </p>
</div>
</div>
<div className="Sr-item z-depth-1 wow fadeInUp delay-1s slower">
<div className="icon-wrap">
<div className="S-icon rounded-circle">
<img src="../../../img/fron-end.png" alt="icons fron-end"
className="img-fluid"/>
</div>
</div>
<div className="S-name">
<h3>Analytics</h3>
<p>Get Insights Into Who Is Browsing Site</p>
</div>
</div>
) ) }
</div>
i want to render all my data in all of these Sr-items blocks, but when i shift closing brackets of map function at the end where i want to close them i makes error
here how error code looks
2
Answers
The problem is that a JSX function can only return a single Element.
You need to wrap the returning elements of the function passed to the
map
with a React Fragment (https://reactjs.org/docs/fragments.html)The problem with your code is that you are returning multiple div inside a single return statement when it should be only one.
Wrap all the div inside one parent div and it will work in the map return statement.
Or
these two lines results are equal.
Also you cannot use hyphen(-) for variable names as you have used
and
Instead these should be:
Or
and
Or
{data.backtEnd_intro}
Checkout this: