Iterate in multiple states while rendering










0














I'm trying to render a component that takes data from a local API and it's been set it into multiple states, at the moment I'm mapping through one state and I need to use some data from another state. How can I access this data and map through it once?



In prodsLink='https://www.sodimac.cl/sodimac-homy/product/' + skuData.productId + '/'



I need to render something like this:



https://www.sodimac.cl/sodimac-homy/product/productID/productLocation



but if I do this:



prodsLink='https://www.sodimac.cl/sodimac-homy/product/' + skuData.productId + '/' + this.state.ids.map(skuMarca => skuMarca.marca)



It will render something like this:



https://www.sodimac.cl/sodimac-homy/product/productID/productLocation01,productLocation02,productLocation03,productLocation04



UPDATE:



This is the output I'm looking for (once per loop not all of them in one array):



<a href="https://www.sodimac.cl/sodimac-homy/product/productID/productLocation01"> BUTTON 01 </a>



<a href="https://www.sodimac.cl/sodimac-homy/product/productID/productLocation02"> BUTTON 02 </a>



<a href="https://www.sodimac.cl/sodimac-homy/product/productID/productLocation03"> BUTTON 03 </a>



<a href="https://www.sodimac.cl/sodimac-homy/product/productID/productLocation04"> BUTTON 04 </a>



I know is confusing so here is my code.



render() 

return (
this.getWebServiceResponse(this.state.ids.map(e => e.sku).join('-'), 96),
this.state.active == true &&
<div className="row" style= width: '89%', margin: '0 auto' >
<div className="blockCatPriceSlide">
this.state.products.map(skuData =>
window.innerWidth > 440 && skuData.status === 'OK' ?
<ContenidoUno
prodsName=skuData.name.substr(0, 30) + '...'
prodsId=skuData.productId
prodsStatus=skuData.status
prodsPublished=skuData.published
prodsNormal=skuData.NORMAL.toLocaleString().replace(',', '.')
prodsCMR=skuData.CMR
prodsCombo=skuData.combo
prodsAhorro=skuData.savings
prodsStock=skuData.stockLevel
prodsAntes=skuData.NORMAL + skuData.savings > skuData.NORMAL ? <small> Antes: $ skuData.NORMAL + skuData.savings </small> : ''.toLocaleString().replace(',', '.')
prodsLink='https://www.sodimac.cl/sodimac-homy/product/' + skuData.productId + '/'
prodsImg='https://picsum.photos/g/570/250'
prodsIcon=
catName=skuData.webCategoryName
/> :
<ContenidoUno
prodsName='Producto sin información...'
prodsId=''
prodsStatus=''
prodsPublished=''
prodsNormal=''
prodsCMR=''
prodsCombo=''
prodsAhorro=''
prodsStock=''
prodsAntes=''
prodsLink=''
prodsImg='https://picsum.photos/g/570/250'
prodsIcon=''
catName=''
/>

)

</div>
</div>
)

}









share|improve this question




























    0














    I'm trying to render a component that takes data from a local API and it's been set it into multiple states, at the moment I'm mapping through one state and I need to use some data from another state. How can I access this data and map through it once?



    In prodsLink='https://www.sodimac.cl/sodimac-homy/product/' + skuData.productId + '/'



    I need to render something like this:



    https://www.sodimac.cl/sodimac-homy/product/productID/productLocation



    but if I do this:



    prodsLink='https://www.sodimac.cl/sodimac-homy/product/' + skuData.productId + '/' + this.state.ids.map(skuMarca => skuMarca.marca)



    It will render something like this:



    https://www.sodimac.cl/sodimac-homy/product/productID/productLocation01,productLocation02,productLocation03,productLocation04



    UPDATE:



    This is the output I'm looking for (once per loop not all of them in one array):



    <a href="https://www.sodimac.cl/sodimac-homy/product/productID/productLocation01"> BUTTON 01 </a>



    <a href="https://www.sodimac.cl/sodimac-homy/product/productID/productLocation02"> BUTTON 02 </a>



    <a href="https://www.sodimac.cl/sodimac-homy/product/productID/productLocation03"> BUTTON 03 </a>



    <a href="https://www.sodimac.cl/sodimac-homy/product/productID/productLocation04"> BUTTON 04 </a>



    I know is confusing so here is my code.



    render() 

    return (
    this.getWebServiceResponse(this.state.ids.map(e => e.sku).join('-'), 96),
    this.state.active == true &&
    <div className="row" style= width: '89%', margin: '0 auto' >
    <div className="blockCatPriceSlide">
    this.state.products.map(skuData =>
    window.innerWidth > 440 && skuData.status === 'OK' ?
    <ContenidoUno
    prodsName=skuData.name.substr(0, 30) + '...'
    prodsId=skuData.productId
    prodsStatus=skuData.status
    prodsPublished=skuData.published
    prodsNormal=skuData.NORMAL.toLocaleString().replace(',', '.')
    prodsCMR=skuData.CMR
    prodsCombo=skuData.combo
    prodsAhorro=skuData.savings
    prodsStock=skuData.stockLevel
    prodsAntes=skuData.NORMAL + skuData.savings > skuData.NORMAL ? <small> Antes: $ skuData.NORMAL + skuData.savings </small> : ''.toLocaleString().replace(',', '.')
    prodsLink='https://www.sodimac.cl/sodimac-homy/product/' + skuData.productId + '/'
    prodsImg='https://picsum.photos/g/570/250'
    prodsIcon=
    catName=skuData.webCategoryName
    /> :
    <ContenidoUno
    prodsName='Producto sin información...'
    prodsId=''
    prodsStatus=''
    prodsPublished=''
    prodsNormal=''
    prodsCMR=''
    prodsCombo=''
    prodsAhorro=''
    prodsStock=''
    prodsAntes=''
    prodsLink=''
    prodsImg='https://picsum.photos/g/570/250'
    prodsIcon=''
    catName=''
    />

    )

    </div>
    </div>
    )

    }









    share|improve this question


























      0












      0








      0







      I'm trying to render a component that takes data from a local API and it's been set it into multiple states, at the moment I'm mapping through one state and I need to use some data from another state. How can I access this data and map through it once?



      In prodsLink='https://www.sodimac.cl/sodimac-homy/product/' + skuData.productId + '/'



      I need to render something like this:



      https://www.sodimac.cl/sodimac-homy/product/productID/productLocation



      but if I do this:



      prodsLink='https://www.sodimac.cl/sodimac-homy/product/' + skuData.productId + '/' + this.state.ids.map(skuMarca => skuMarca.marca)



      It will render something like this:



      https://www.sodimac.cl/sodimac-homy/product/productID/productLocation01,productLocation02,productLocation03,productLocation04



      UPDATE:



      This is the output I'm looking for (once per loop not all of them in one array):



      <a href="https://www.sodimac.cl/sodimac-homy/product/productID/productLocation01"> BUTTON 01 </a>



      <a href="https://www.sodimac.cl/sodimac-homy/product/productID/productLocation02"> BUTTON 02 </a>



      <a href="https://www.sodimac.cl/sodimac-homy/product/productID/productLocation03"> BUTTON 03 </a>



      <a href="https://www.sodimac.cl/sodimac-homy/product/productID/productLocation04"> BUTTON 04 </a>



      I know is confusing so here is my code.



      render() 

      return (
      this.getWebServiceResponse(this.state.ids.map(e => e.sku).join('-'), 96),
      this.state.active == true &&
      <div className="row" style= width: '89%', margin: '0 auto' >
      <div className="blockCatPriceSlide">
      this.state.products.map(skuData =>
      window.innerWidth > 440 && skuData.status === 'OK' ?
      <ContenidoUno
      prodsName=skuData.name.substr(0, 30) + '...'
      prodsId=skuData.productId
      prodsStatus=skuData.status
      prodsPublished=skuData.published
      prodsNormal=skuData.NORMAL.toLocaleString().replace(',', '.')
      prodsCMR=skuData.CMR
      prodsCombo=skuData.combo
      prodsAhorro=skuData.savings
      prodsStock=skuData.stockLevel
      prodsAntes=skuData.NORMAL + skuData.savings > skuData.NORMAL ? <small> Antes: $ skuData.NORMAL + skuData.savings </small> : ''.toLocaleString().replace(',', '.')
      prodsLink='https://www.sodimac.cl/sodimac-homy/product/' + skuData.productId + '/'
      prodsImg='https://picsum.photos/g/570/250'
      prodsIcon=
      catName=skuData.webCategoryName
      /> :
      <ContenidoUno
      prodsName='Producto sin información...'
      prodsId=''
      prodsStatus=''
      prodsPublished=''
      prodsNormal=''
      prodsCMR=''
      prodsCombo=''
      prodsAhorro=''
      prodsStock=''
      prodsAntes=''
      prodsLink=''
      prodsImg='https://picsum.photos/g/570/250'
      prodsIcon=''
      catName=''
      />

      )

      </div>
      </div>
      )

      }









      share|improve this question















      I'm trying to render a component that takes data from a local API and it's been set it into multiple states, at the moment I'm mapping through one state and I need to use some data from another state. How can I access this data and map through it once?



      In prodsLink='https://www.sodimac.cl/sodimac-homy/product/' + skuData.productId + '/'



      I need to render something like this:



      https://www.sodimac.cl/sodimac-homy/product/productID/productLocation



      but if I do this:



      prodsLink='https://www.sodimac.cl/sodimac-homy/product/' + skuData.productId + '/' + this.state.ids.map(skuMarca => skuMarca.marca)



      It will render something like this:



      https://www.sodimac.cl/sodimac-homy/product/productID/productLocation01,productLocation02,productLocation03,productLocation04



      UPDATE:



      This is the output I'm looking for (once per loop not all of them in one array):



      <a href="https://www.sodimac.cl/sodimac-homy/product/productID/productLocation01"> BUTTON 01 </a>



      <a href="https://www.sodimac.cl/sodimac-homy/product/productID/productLocation02"> BUTTON 02 </a>



      <a href="https://www.sodimac.cl/sodimac-homy/product/productID/productLocation03"> BUTTON 03 </a>



      <a href="https://www.sodimac.cl/sodimac-homy/product/productID/productLocation04"> BUTTON 04 </a>



      I know is confusing so here is my code.



      render() 

      return (
      this.getWebServiceResponse(this.state.ids.map(e => e.sku).join('-'), 96),
      this.state.active == true &&
      <div className="row" style= width: '89%', margin: '0 auto' >
      <div className="blockCatPriceSlide">
      this.state.products.map(skuData =>
      window.innerWidth > 440 && skuData.status === 'OK' ?
      <ContenidoUno
      prodsName=skuData.name.substr(0, 30) + '...'
      prodsId=skuData.productId
      prodsStatus=skuData.status
      prodsPublished=skuData.published
      prodsNormal=skuData.NORMAL.toLocaleString().replace(',', '.')
      prodsCMR=skuData.CMR
      prodsCombo=skuData.combo
      prodsAhorro=skuData.savings
      prodsStock=skuData.stockLevel
      prodsAntes=skuData.NORMAL + skuData.savings > skuData.NORMAL ? <small> Antes: $ skuData.NORMAL + skuData.savings </small> : ''.toLocaleString().replace(',', '.')
      prodsLink='https://www.sodimac.cl/sodimac-homy/product/' + skuData.productId + '/'
      prodsImg='https://picsum.photos/g/570/250'
      prodsIcon=
      catName=skuData.webCategoryName
      /> :
      <ContenidoUno
      prodsName='Producto sin información...'
      prodsId=''
      prodsStatus=''
      prodsPublished=''
      prodsNormal=''
      prodsCMR=''
      prodsCombo=''
      prodsAhorro=''
      prodsStock=''
      prodsAntes=''
      prodsLink=''
      prodsImg='https://picsum.photos/g/570/250'
      prodsIcon=''
      catName=''
      />

      )

      </div>
      </div>
      )

      }






      reactjs babeljs






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 17:42

























      asked Nov 12 at 14:16









      Daniel Rebolledo

      34




      34






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Array.prototype.map returns a new array, so in this situation you're just returning array of [marca?, marca?, ...], so instead of returning, marca? from map you should returning whole link like so:



          prodsLink= this.state.ids.map(( marca ) =>
          `https://www.sodimac.cl/sodimac-homy/product/$skuData.productId/$marca`
          )


          this will generate link array:



          [



          https://www.sodimac.cl/sodimac-homy/product/$skuData.productId/$marca,
          https://www.sodimac.cl/sodimac-homy/product/$skuData.productId/$marca,
          https://www.sodimac.cl/sodimac-homy/product/$skuData.productId/$marca,



          ...



          ]






          share|improve this answer




















          • It's creating a link with all the links inside: sodimac.cl/sodimac-homy/product/productID/marca,https://…
            – Daniel Rebolledo
            Nov 12 at 15:36











          • It's creating a link array, you should edit a question and specify what's your desired output.
            – Simas.B
            Nov 12 at 15:47










          • Question updated...
            – Daniel Rebolledo
            Nov 12 at 18:02










          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%2f53264046%2fiterate-in-multiple-states-while-rendering%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Array.prototype.map returns a new array, so in this situation you're just returning array of [marca?, marca?, ...], so instead of returning, marca? from map you should returning whole link like so:



          prodsLink= this.state.ids.map(( marca ) =>
          `https://www.sodimac.cl/sodimac-homy/product/$skuData.productId/$marca`
          )


          this will generate link array:



          [



          https://www.sodimac.cl/sodimac-homy/product/$skuData.productId/$marca,
          https://www.sodimac.cl/sodimac-homy/product/$skuData.productId/$marca,
          https://www.sodimac.cl/sodimac-homy/product/$skuData.productId/$marca,



          ...



          ]






          share|improve this answer




















          • It's creating a link with all the links inside: sodimac.cl/sodimac-homy/product/productID/marca,https://…
            – Daniel Rebolledo
            Nov 12 at 15:36











          • It's creating a link array, you should edit a question and specify what's your desired output.
            – Simas.B
            Nov 12 at 15:47










          • Question updated...
            – Daniel Rebolledo
            Nov 12 at 18:02















          0














          Array.prototype.map returns a new array, so in this situation you're just returning array of [marca?, marca?, ...], so instead of returning, marca? from map you should returning whole link like so:



          prodsLink= this.state.ids.map(( marca ) =>
          `https://www.sodimac.cl/sodimac-homy/product/$skuData.productId/$marca`
          )


          this will generate link array:



          [



          https://www.sodimac.cl/sodimac-homy/product/$skuData.productId/$marca,
          https://www.sodimac.cl/sodimac-homy/product/$skuData.productId/$marca,
          https://www.sodimac.cl/sodimac-homy/product/$skuData.productId/$marca,



          ...



          ]






          share|improve this answer




















          • It's creating a link with all the links inside: sodimac.cl/sodimac-homy/product/productID/marca,https://…
            – Daniel Rebolledo
            Nov 12 at 15:36











          • It's creating a link array, you should edit a question and specify what's your desired output.
            – Simas.B
            Nov 12 at 15:47










          • Question updated...
            – Daniel Rebolledo
            Nov 12 at 18:02













          0












          0








          0






          Array.prototype.map returns a new array, so in this situation you're just returning array of [marca?, marca?, ...], so instead of returning, marca? from map you should returning whole link like so:



          prodsLink= this.state.ids.map(( marca ) =>
          `https://www.sodimac.cl/sodimac-homy/product/$skuData.productId/$marca`
          )


          this will generate link array:



          [



          https://www.sodimac.cl/sodimac-homy/product/$skuData.productId/$marca,
          https://www.sodimac.cl/sodimac-homy/product/$skuData.productId/$marca,
          https://www.sodimac.cl/sodimac-homy/product/$skuData.productId/$marca,



          ...



          ]






          share|improve this answer












          Array.prototype.map returns a new array, so in this situation you're just returning array of [marca?, marca?, ...], so instead of returning, marca? from map you should returning whole link like so:



          prodsLink= this.state.ids.map(( marca ) =>
          `https://www.sodimac.cl/sodimac-homy/product/$skuData.productId/$marca`
          )


          this will generate link array:



          [



          https://www.sodimac.cl/sodimac-homy/product/$skuData.productId/$marca,
          https://www.sodimac.cl/sodimac-homy/product/$skuData.productId/$marca,
          https://www.sodimac.cl/sodimac-homy/product/$skuData.productId/$marca,



          ...



          ]







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 at 15:15









          Simas.B

          18014




          18014











          • It's creating a link with all the links inside: sodimac.cl/sodimac-homy/product/productID/marca,https://…
            – Daniel Rebolledo
            Nov 12 at 15:36











          • It's creating a link array, you should edit a question and specify what's your desired output.
            – Simas.B
            Nov 12 at 15:47










          • Question updated...
            – Daniel Rebolledo
            Nov 12 at 18:02
















          • It's creating a link with all the links inside: sodimac.cl/sodimac-homy/product/productID/marca,https://…
            – Daniel Rebolledo
            Nov 12 at 15:36











          • It's creating a link array, you should edit a question and specify what's your desired output.
            – Simas.B
            Nov 12 at 15:47










          • Question updated...
            – Daniel Rebolledo
            Nov 12 at 18:02















          It's creating a link with all the links inside: sodimac.cl/sodimac-homy/product/productID/marca,https://…
          – Daniel Rebolledo
          Nov 12 at 15:36





          It's creating a link with all the links inside: sodimac.cl/sodimac-homy/product/productID/marca,https://…
          – Daniel Rebolledo
          Nov 12 at 15:36













          It's creating a link array, you should edit a question and specify what's your desired output.
          – Simas.B
          Nov 12 at 15:47




          It's creating a link array, you should edit a question and specify what's your desired output.
          – Simas.B
          Nov 12 at 15:47












          Question updated...
          – Daniel Rebolledo
          Nov 12 at 18:02




          Question updated...
          – Daniel Rebolledo
          Nov 12 at 18:02

















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f53264046%2fiterate-in-multiple-states-while-rendering%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







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3

          Museum of Modern and Contemporary Art of Trento and Rovereto