Return jsx using the map function












0















I am new to react-redux. Here what I am doing is ,



return analitics.map(analiticss => (
<div className="col-md-8 d-flex justify-content-around questionDetailRow1">
<div>
<span>
<i
className="fa fa-check-circle"
style={{ fontSize: "24px", color: "green" }}
/>
</span>
<span className="ml-2">
{analitics.wrong ? `${analitics.wrong}` : "0"}
</span>
</div>
<div>
<span>
<i
class="fa fa-times-circle"
style={{ fontSize: "24px", color: "red" }}
/>
</span>
<span className="ml-2">{analiticss.wrong}</span>
</div>
<div>
<span className="skip-background">
<i className="fa fa-fast-forward" style={{ color: "black" }} />
</span>
<span className="ml-2">{analiticss.skipped}</span>
</div>
<button type="button" className="btn btn-outline-primary">
Change
</button>
</div>
));


So, here I want to have this div on any condition. so what happens is ,



if the analiticss is not present then this will not get return. Because that there is no element to iterate.



so, I want to show that values as a `0.{analiticss.skipped} this values.



But it does not return this element as it does not have any array element.



One solution that I have is to use if else with expplicitely adding same html in this with 0 values.



But I don't think its a right solution. is there any onther solution that I can use ?










share|improve this question





























    0















    I am new to react-redux. Here what I am doing is ,



    return analitics.map(analiticss => (
    <div className="col-md-8 d-flex justify-content-around questionDetailRow1">
    <div>
    <span>
    <i
    className="fa fa-check-circle"
    style={{ fontSize: "24px", color: "green" }}
    />
    </span>
    <span className="ml-2">
    {analitics.wrong ? `${analitics.wrong}` : "0"}
    </span>
    </div>
    <div>
    <span>
    <i
    class="fa fa-times-circle"
    style={{ fontSize: "24px", color: "red" }}
    />
    </span>
    <span className="ml-2">{analiticss.wrong}</span>
    </div>
    <div>
    <span className="skip-background">
    <i className="fa fa-fast-forward" style={{ color: "black" }} />
    </span>
    <span className="ml-2">{analiticss.skipped}</span>
    </div>
    <button type="button" className="btn btn-outline-primary">
    Change
    </button>
    </div>
    ));


    So, here I want to have this div on any condition. so what happens is ,



    if the analiticss is not present then this will not get return. Because that there is no element to iterate.



    so, I want to show that values as a `0.{analiticss.skipped} this values.



    But it does not return this element as it does not have any array element.



    One solution that I have is to use if else with expplicitely adding same html in this with 0 values.



    But I don't think its a right solution. is there any onther solution that I can use ?










    share|improve this question



























      0












      0








      0








      I am new to react-redux. Here what I am doing is ,



      return analitics.map(analiticss => (
      <div className="col-md-8 d-flex justify-content-around questionDetailRow1">
      <div>
      <span>
      <i
      className="fa fa-check-circle"
      style={{ fontSize: "24px", color: "green" }}
      />
      </span>
      <span className="ml-2">
      {analitics.wrong ? `${analitics.wrong}` : "0"}
      </span>
      </div>
      <div>
      <span>
      <i
      class="fa fa-times-circle"
      style={{ fontSize: "24px", color: "red" }}
      />
      </span>
      <span className="ml-2">{analiticss.wrong}</span>
      </div>
      <div>
      <span className="skip-background">
      <i className="fa fa-fast-forward" style={{ color: "black" }} />
      </span>
      <span className="ml-2">{analiticss.skipped}</span>
      </div>
      <button type="button" className="btn btn-outline-primary">
      Change
      </button>
      </div>
      ));


      So, here I want to have this div on any condition. so what happens is ,



      if the analiticss is not present then this will not get return. Because that there is no element to iterate.



      so, I want to show that values as a `0.{analiticss.skipped} this values.



      But it does not return this element as it does not have any array element.



      One solution that I have is to use if else with expplicitely adding same html in this with 0 values.



      But I don't think its a right solution. is there any onther solution that I can use ?










      share|improve this question
















      I am new to react-redux. Here what I am doing is ,



      return analitics.map(analiticss => (
      <div className="col-md-8 d-flex justify-content-around questionDetailRow1">
      <div>
      <span>
      <i
      className="fa fa-check-circle"
      style={{ fontSize: "24px", color: "green" }}
      />
      </span>
      <span className="ml-2">
      {analitics.wrong ? `${analitics.wrong}` : "0"}
      </span>
      </div>
      <div>
      <span>
      <i
      class="fa fa-times-circle"
      style={{ fontSize: "24px", color: "red" }}
      />
      </span>
      <span className="ml-2">{analiticss.wrong}</span>
      </div>
      <div>
      <span className="skip-background">
      <i className="fa fa-fast-forward" style={{ color: "black" }} />
      </span>
      <span className="ml-2">{analiticss.skipped}</span>
      </div>
      <button type="button" className="btn btn-outline-primary">
      Change
      </button>
      </div>
      ));


      So, here I want to have this div on any condition. so what happens is ,



      if the analiticss is not present then this will not get return. Because that there is no element to iterate.



      so, I want to show that values as a `0.{analiticss.skipped} this values.



      But it does not return this element as it does not have any array element.



      One solution that I have is to use if else with expplicitely adding same html in this with 0 values.



      But I don't think its a right solution. is there any onther solution that I can use ?







      javascript reactjs redux react-redux






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 '18 at 11:17









      Tholle

      34.1k53760




      34.1k53760










      asked Nov 20 '18 at 11:15









      ganesh kaspateganesh kaspate

      21119




      21119
























          2 Answers
          2






          active

          oldest

          votes


















          0














          If you want to still have the wrapper div visible, you need to move the map function inside of the wrapper div.
          Something like:



          <div className="col-md-8 d-flex justify-content-around questionDetailRow1">
          {analytics.map(...)}
          </div>






          share|improve this answer
























          • Not wrapper div only, everything which is in the div

            – ganesh kaspate
            Nov 20 '18 at 11:25



















          0














          You can try this Sandbox Link.



          I have added your code and there is no data inside the analytics.



          https://codesandbox.io/s/zwr8391y24



          Still you will see the Skipped






          share|improve this answer
























          • I dont want to have just div, also want to have the data manipulation divs as well. but the values will get set to 0.

            – ganesh kaspate
            Nov 20 '18 at 11:29











          • Which divs are for data manipulation?

            – Harish Soni
            Nov 20 '18 at 11:31













          • Did you tried the Sandbox link @ganeshkaspate???

            – Harish Soni
            Nov 20 '18 at 11:33











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391817%2freturn-jsx-using-the-map-function%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          If you want to still have the wrapper div visible, you need to move the map function inside of the wrapper div.
          Something like:



          <div className="col-md-8 d-flex justify-content-around questionDetailRow1">
          {analytics.map(...)}
          </div>






          share|improve this answer
























          • Not wrapper div only, everything which is in the div

            – ganesh kaspate
            Nov 20 '18 at 11:25
















          0














          If you want to still have the wrapper div visible, you need to move the map function inside of the wrapper div.
          Something like:



          <div className="col-md-8 d-flex justify-content-around questionDetailRow1">
          {analytics.map(...)}
          </div>






          share|improve this answer
























          • Not wrapper div only, everything which is in the div

            – ganesh kaspate
            Nov 20 '18 at 11:25














          0












          0








          0







          If you want to still have the wrapper div visible, you need to move the map function inside of the wrapper div.
          Something like:



          <div className="col-md-8 d-flex justify-content-around questionDetailRow1">
          {analytics.map(...)}
          </div>






          share|improve this answer













          If you want to still have the wrapper div visible, you need to move the map function inside of the wrapper div.
          Something like:



          <div className="col-md-8 d-flex justify-content-around questionDetailRow1">
          {analytics.map(...)}
          </div>







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 '18 at 11:20









          Gilad BarGilad Bar

          643314




          643314













          • Not wrapper div only, everything which is in the div

            – ganesh kaspate
            Nov 20 '18 at 11:25



















          • Not wrapper div only, everything which is in the div

            – ganesh kaspate
            Nov 20 '18 at 11:25

















          Not wrapper div only, everything which is in the div

          – ganesh kaspate
          Nov 20 '18 at 11:25





          Not wrapper div only, everything which is in the div

          – ganesh kaspate
          Nov 20 '18 at 11:25













          0














          You can try this Sandbox Link.



          I have added your code and there is no data inside the analytics.



          https://codesandbox.io/s/zwr8391y24



          Still you will see the Skipped






          share|improve this answer
























          • I dont want to have just div, also want to have the data manipulation divs as well. but the values will get set to 0.

            – ganesh kaspate
            Nov 20 '18 at 11:29











          • Which divs are for data manipulation?

            – Harish Soni
            Nov 20 '18 at 11:31













          • Did you tried the Sandbox link @ganeshkaspate???

            – Harish Soni
            Nov 20 '18 at 11:33
















          0














          You can try this Sandbox Link.



          I have added your code and there is no data inside the analytics.



          https://codesandbox.io/s/zwr8391y24



          Still you will see the Skipped






          share|improve this answer
























          • I dont want to have just div, also want to have the data manipulation divs as well. but the values will get set to 0.

            – ganesh kaspate
            Nov 20 '18 at 11:29











          • Which divs are for data manipulation?

            – Harish Soni
            Nov 20 '18 at 11:31













          • Did you tried the Sandbox link @ganeshkaspate???

            – Harish Soni
            Nov 20 '18 at 11:33














          0












          0








          0







          You can try this Sandbox Link.



          I have added your code and there is no data inside the analytics.



          https://codesandbox.io/s/zwr8391y24



          Still you will see the Skipped






          share|improve this answer













          You can try this Sandbox Link.



          I have added your code and there is no data inside the analytics.



          https://codesandbox.io/s/zwr8391y24



          Still you will see the Skipped







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 '18 at 11:23









          Harish SoniHarish Soni

          859220




          859220













          • I dont want to have just div, also want to have the data manipulation divs as well. but the values will get set to 0.

            – ganesh kaspate
            Nov 20 '18 at 11:29











          • Which divs are for data manipulation?

            – Harish Soni
            Nov 20 '18 at 11:31













          • Did you tried the Sandbox link @ganeshkaspate???

            – Harish Soni
            Nov 20 '18 at 11:33



















          • I dont want to have just div, also want to have the data manipulation divs as well. but the values will get set to 0.

            – ganesh kaspate
            Nov 20 '18 at 11:29











          • Which divs are for data manipulation?

            – Harish Soni
            Nov 20 '18 at 11:31













          • Did you tried the Sandbox link @ganeshkaspate???

            – Harish Soni
            Nov 20 '18 at 11:33

















          I dont want to have just div, also want to have the data manipulation divs as well. but the values will get set to 0.

          – ganesh kaspate
          Nov 20 '18 at 11:29





          I dont want to have just div, also want to have the data manipulation divs as well. but the values will get set to 0.

          – ganesh kaspate
          Nov 20 '18 at 11:29













          Which divs are for data manipulation?

          – Harish Soni
          Nov 20 '18 at 11:31







          Which divs are for data manipulation?

          – Harish Soni
          Nov 20 '18 at 11:31















          Did you tried the Sandbox link @ganeshkaspate???

          – Harish Soni
          Nov 20 '18 at 11:33





          Did you tried the Sandbox link @ganeshkaspate???

          – Harish Soni
          Nov 20 '18 at 11:33


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391817%2freturn-jsx-using-the-map-function%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith