iteration over array for rendering dynamic data without div element [duplicate]











up vote
0
down vote

favorite













This question already has an answer here:




  • How to return multiple lines JSX in another return statement in React?

    6 answers



  • How to avoid extra wrapping <div> in React?

    7 answers




{ Object.keys(props.data).map((key, value) => {


return(
<div>
<dt className="col-sm-3">{key}</dt>
<dd className="col-sm-9">{props.data[key]}</dd>
</div>
)
})}


The above code creating the following:



Key
Value


when hardcoding the above without the div wrapper element i'm getting:



Key           value


the full code chunk:



 <div className="row">
<div className="col-lg-6">
<div className="mb-5">
<h5 className="text-black">
<strong>{props.title}</strong>
</h5>
<dl className="row">
<dt className="col-sm-3">A</dt>
<dd className="col-sm-9">A</dd>
</dl>
</div>
</div>
</div>


So my issue id the div wrapper element, is there a way to use map for rendering dynamic data without returning the div wrapper element?










share|improve this question













marked as duplicate by Shubham Khatri javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 at 14:24


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 2




    You can use React.Fragment to wrap your elements.
    – Tholle
    Nov 19 at 14:23

















up vote
0
down vote

favorite













This question already has an answer here:




  • How to return multiple lines JSX in another return statement in React?

    6 answers



  • How to avoid extra wrapping <div> in React?

    7 answers




{ Object.keys(props.data).map((key, value) => {


return(
<div>
<dt className="col-sm-3">{key}</dt>
<dd className="col-sm-9">{props.data[key]}</dd>
</div>
)
})}


The above code creating the following:



Key
Value


when hardcoding the above without the div wrapper element i'm getting:



Key           value


the full code chunk:



 <div className="row">
<div className="col-lg-6">
<div className="mb-5">
<h5 className="text-black">
<strong>{props.title}</strong>
</h5>
<dl className="row">
<dt className="col-sm-3">A</dt>
<dd className="col-sm-9">A</dd>
</dl>
</div>
</div>
</div>


So my issue id the div wrapper element, is there a way to use map for rendering dynamic data without returning the div wrapper element?










share|improve this question













marked as duplicate by Shubham Khatri javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 at 14:24


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 2




    You can use React.Fragment to wrap your elements.
    – Tholle
    Nov 19 at 14:23















up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:




  • How to return multiple lines JSX in another return statement in React?

    6 answers



  • How to avoid extra wrapping <div> in React?

    7 answers




{ Object.keys(props.data).map((key, value) => {


return(
<div>
<dt className="col-sm-3">{key}</dt>
<dd className="col-sm-9">{props.data[key]}</dd>
</div>
)
})}


The above code creating the following:



Key
Value


when hardcoding the above without the div wrapper element i'm getting:



Key           value


the full code chunk:



 <div className="row">
<div className="col-lg-6">
<div className="mb-5">
<h5 className="text-black">
<strong>{props.title}</strong>
</h5>
<dl className="row">
<dt className="col-sm-3">A</dt>
<dd className="col-sm-9">A</dd>
</dl>
</div>
</div>
</div>


So my issue id the div wrapper element, is there a way to use map for rendering dynamic data without returning the div wrapper element?










share|improve this question














This question already has an answer here:




  • How to return multiple lines JSX in another return statement in React?

    6 answers



  • How to avoid extra wrapping <div> in React?

    7 answers




{ Object.keys(props.data).map((key, value) => {


return(
<div>
<dt className="col-sm-3">{key}</dt>
<dd className="col-sm-9">{props.data[key]}</dd>
</div>
)
})}


The above code creating the following:



Key
Value


when hardcoding the above without the div wrapper element i'm getting:



Key           value


the full code chunk:



 <div className="row">
<div className="col-lg-6">
<div className="mb-5">
<h5 className="text-black">
<strong>{props.title}</strong>
</h5>
<dl className="row">
<dt className="col-sm-3">A</dt>
<dd className="col-sm-9">A</dd>
</dl>
</div>
</div>
</div>


So my issue id the div wrapper element, is there a way to use map for rendering dynamic data without returning the div wrapper element?





This question already has an answer here:




  • How to return multiple lines JSX in another return statement in React?

    6 answers



  • How to avoid extra wrapping <div> in React?

    7 answers








javascript reactjs






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 14:19









USer22999299

1,48722252




1,48722252




marked as duplicate by Shubham Khatri javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 at 14:24


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Shubham Khatri javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 at 14:24


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 2




    You can use React.Fragment to wrap your elements.
    – Tholle
    Nov 19 at 14:23
















  • 2




    You can use React.Fragment to wrap your elements.
    – Tholle
    Nov 19 at 14:23










2




2




You can use React.Fragment to wrap your elements.
– Tholle
Nov 19 at 14:23






You can use React.Fragment to wrap your elements.
– Tholle
Nov 19 at 14:23














1 Answer
1






active

oldest

votes

















up vote
0
down vote













Thinking semantically, it would be good idea to wrap with dl:



return(
<dl>
<dt className="col-sm-3">{key}</dt>
<dd className="col-sm-9">{props.data[key]}</dd>
</dl>
)


But looking at the code you're already defining dl and inside that you're using the component?



If you don't like the above solution only then you should use React.Fragment: (Use the above as far as possible)



return(
<> {/* alias for React.Fragment */}
<dt className="col-sm-3">{key}</dt>
<dd className="col-sm-9">{props.data[key]}</dd>
</>
)




Ah, you also need to provide key props:



<dl key={key}>


Or, using Fragment:



<React.Fragment key={key}>


The following is invalid use: (shorthand method doesn't support any props)



<key={key>
</>





share|improve this answer























  • still the same issue...
    – USer22999299
    Nov 19 at 14:31










  • Updated my answer.
    – Bhojendra Rauniyar
    Nov 19 at 14:35


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Thinking semantically, it would be good idea to wrap with dl:



return(
<dl>
<dt className="col-sm-3">{key}</dt>
<dd className="col-sm-9">{props.data[key]}</dd>
</dl>
)


But looking at the code you're already defining dl and inside that you're using the component?



If you don't like the above solution only then you should use React.Fragment: (Use the above as far as possible)



return(
<> {/* alias for React.Fragment */}
<dt className="col-sm-3">{key}</dt>
<dd className="col-sm-9">{props.data[key]}</dd>
</>
)




Ah, you also need to provide key props:



<dl key={key}>


Or, using Fragment:



<React.Fragment key={key}>


The following is invalid use: (shorthand method doesn't support any props)



<key={key>
</>





share|improve this answer























  • still the same issue...
    – USer22999299
    Nov 19 at 14:31










  • Updated my answer.
    – Bhojendra Rauniyar
    Nov 19 at 14:35















up vote
0
down vote













Thinking semantically, it would be good idea to wrap with dl:



return(
<dl>
<dt className="col-sm-3">{key}</dt>
<dd className="col-sm-9">{props.data[key]}</dd>
</dl>
)


But looking at the code you're already defining dl and inside that you're using the component?



If you don't like the above solution only then you should use React.Fragment: (Use the above as far as possible)



return(
<> {/* alias for React.Fragment */}
<dt className="col-sm-3">{key}</dt>
<dd className="col-sm-9">{props.data[key]}</dd>
</>
)




Ah, you also need to provide key props:



<dl key={key}>


Or, using Fragment:



<React.Fragment key={key}>


The following is invalid use: (shorthand method doesn't support any props)



<key={key>
</>





share|improve this answer























  • still the same issue...
    – USer22999299
    Nov 19 at 14:31










  • Updated my answer.
    – Bhojendra Rauniyar
    Nov 19 at 14:35













up vote
0
down vote










up vote
0
down vote









Thinking semantically, it would be good idea to wrap with dl:



return(
<dl>
<dt className="col-sm-3">{key}</dt>
<dd className="col-sm-9">{props.data[key]}</dd>
</dl>
)


But looking at the code you're already defining dl and inside that you're using the component?



If you don't like the above solution only then you should use React.Fragment: (Use the above as far as possible)



return(
<> {/* alias for React.Fragment */}
<dt className="col-sm-3">{key}</dt>
<dd className="col-sm-9">{props.data[key]}</dd>
</>
)




Ah, you also need to provide key props:



<dl key={key}>


Or, using Fragment:



<React.Fragment key={key}>


The following is invalid use: (shorthand method doesn't support any props)



<key={key>
</>





share|improve this answer














Thinking semantically, it would be good idea to wrap with dl:



return(
<dl>
<dt className="col-sm-3">{key}</dt>
<dd className="col-sm-9">{props.data[key]}</dd>
</dl>
)


But looking at the code you're already defining dl and inside that you're using the component?



If you don't like the above solution only then you should use React.Fragment: (Use the above as far as possible)



return(
<> {/* alias for React.Fragment */}
<dt className="col-sm-3">{key}</dt>
<dd className="col-sm-9">{props.data[key]}</dd>
</>
)




Ah, you also need to provide key props:



<dl key={key}>


Or, using Fragment:



<React.Fragment key={key}>


The following is invalid use: (shorthand method doesn't support any props)



<key={key>
</>






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 at 14:34

























answered Nov 19 at 14:25









Bhojendra Rauniyar

49.5k1977120




49.5k1977120












  • still the same issue...
    – USer22999299
    Nov 19 at 14:31










  • Updated my answer.
    – Bhojendra Rauniyar
    Nov 19 at 14:35


















  • still the same issue...
    – USer22999299
    Nov 19 at 14:31










  • Updated my answer.
    – Bhojendra Rauniyar
    Nov 19 at 14:35
















still the same issue...
– USer22999299
Nov 19 at 14:31




still the same issue...
– USer22999299
Nov 19 at 14:31












Updated my answer.
– Bhojendra Rauniyar
Nov 19 at 14:35




Updated my answer.
– Bhojendra Rauniyar
Nov 19 at 14:35



Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen