<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jose Moreno Gomez</title>
    <description>The latest articles on DEV Community by Jose Moreno Gomez (@josemgux).</description>
    <link>https://dev.to/josemgux</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F402287%2F1817d64e-9d7f-4f10-ab24-8c1a5f6ef472.jpeg</url>
      <title>DEV Community: Jose Moreno Gomez</title>
      <link>https://dev.to/josemgux</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/josemgux"/>
    <language>en</language>
    <item>
      <title>Avoid rendering component of each API call
</title>
      <dc:creator>Jose Moreno Gomez</dc:creator>
      <pubDate>Tue, 26 Oct 2021 17:24:52 +0000</pubDate>
      <link>https://dev.to/josemgux/avoid-rendering-component-of-each-api-call-28f7</link>
      <guid>https://dev.to/josemgux/avoid-rendering-component-of-each-api-call-28f7</guid>
      <description>&lt;p&gt;I'm something new to React and something is happening to me that I imagine is simple for someone experienced. I'm filling a table with an api and then I download that table into a pdf file and each table into a different page.&lt;/p&gt;

&lt;p&gt;I make more than one call to an api then the info that I bring the mapping in a component and then I render it, what is happening to me is that I am rendering 1 component for each call or so if I make 100 calls to the api it renders me 100 components and I do not want that. What do I want?, That I render only 1 component in the DOM but when I download that file if it comes with all the tables (Components) of all the calls I made.&lt;/p&gt;

&lt;p&gt;It is rendering me a component in the DOM for each iteration in the array that has the API information.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState, useEffect, useRef } from 'react';
import axios from 'axios';
import { Table, Button } from 'reactstrap';
import { PDFExport } from '@progress/kendo-react-pdf';

const styles = {
  title: {
    textAlign: 'center',
    fontSize: '20px',
    fontWeight: 'bold',
  },
  subtitle: {
    textAlign: 'center',
    background: '#67B71F',
    color: 'white',
    fontSize: '15px',
  },

  td: {
    fontSize: '15px',
  },
  th: {
    fontSize: '15px',
    fontWeight: 'bold',
  },
  button: {
    fontWeight: 'bold',
  },
};
const options = {
  headers: {
    Authorization: process.env.REACT_APP_GETTOKENPDF,
  },
};

const BlankPage = () =&amp;gt; {
  const pdfExportComponent = useRef(null);
  const [InfoData, setInfoData] = useState([]);

  useEffect(() =&amp;gt; {
    const apiURL = `${process.env.REACT_APP_URL_PDF}?conditional=idMerchant$in28::4193`;
    axios
      .get(`${apiURL}`, options)

      .then(({ data }) =&amp;gt; {
        setInfoData(data.data);
      })
      .catch((error) =&amp;gt; {
        console.log('Alerta error: ', error.data);
      });
  }, []);

  const Registers = () =&amp;gt; (
    &amp;lt;&amp;gt;
      {InfoData.map((res) =&amp;gt; (
        &amp;lt;div className="card text-left " key={res.idMerchant}&amp;gt;
          &amp;lt;PDFExport forcePageBreak=".page-break"&amp;gt;
            &amp;lt;Table className="table table-bordered"&amp;gt;
              {/* &amp;lt;caption style={styles.title}&amp;gt;INFORMACION DE REGISTRO&amp;lt;/caption&amp;gt; */}
              &amp;lt;tbody&amp;gt;
                &amp;lt;tr&amp;gt;
                  &amp;lt;td style={styles.th} colSpan="1"&amp;gt;
                    Nombre de la Cuenta:
                  &amp;lt;/td&amp;gt;
                  &amp;lt;td style={styles.td}&amp;gt;{res.merchantName}&amp;lt;/td&amp;gt;
                  &amp;lt;td style={styles.th}&amp;gt;ID:&amp;lt;/td&amp;gt;
                  &amp;lt;td style={styles.td}&amp;gt;{res.idMerchant}&amp;lt;/td&amp;gt;
                &amp;lt;/tr&amp;gt;
                &amp;lt;tr&amp;gt;
                  &amp;lt;td style={styles.th}&amp;gt;Usuario que registro la cuenta:&amp;lt;/td&amp;gt;
                  &amp;lt;td style={styles.td}&amp;gt;{res.officerUpdate}&amp;lt;/td&amp;gt;
                  &amp;lt;td style={styles.th}&amp;gt;Fecha:&amp;lt;/td&amp;gt;
                  &amp;lt;td style={styles.td}&amp;gt;{res.activationDate}&amp;lt;/td&amp;gt;
                &amp;lt;/tr&amp;gt;
                &amp;lt;tr&amp;gt;
                  &amp;lt;td style={styles.th}&amp;gt;Tipo de cuenta:&amp;lt;/td&amp;gt;
                  &amp;lt;td style={styles.td}&amp;gt;{res.merchantType}&amp;lt;/td&amp;gt;
                &amp;lt;/tr&amp;gt;
                &amp;lt;tr&amp;gt;
                  &amp;lt;td style={styles.td} colSpan="4"&amp;gt;
                    Los terminos y condiciones son aceptados por defecto al
                    momento del registro de la cuenta.
                    &amp;lt;a href="https://www.paguelofacil.com/terminos-y-condiciones"&amp;gt;
                      &amp;lt;br /&amp;gt;
                      https://www.paguelofacil.com/terminos-y-condiciones
                    &amp;lt;/a&amp;gt;
                  &amp;lt;/td&amp;gt;
                &amp;lt;/tr&amp;gt;               
                &amp;lt;/tr&amp;gt;
              &amp;lt;/tbody&amp;gt;
            &amp;lt;/Table&amp;gt;
          &amp;lt;/PDFExport&amp;gt;
        &amp;lt;/div&amp;gt;
      ))}
    &amp;lt;/&amp;gt;
  );

  return (
    &amp;lt;&amp;gt;
      &amp;lt;PDFExport
        forcePageBreak=".page-break"
        fileName="Archivo.pdf"
        scale={0.9}
        paperSize="a4"
        keepTogether="Table"
        ref={pdfExportComponent}
      &amp;gt;
        &amp;lt;Registers /&amp;gt;
      &amp;lt;/PDFExport&amp;gt;
      &amp;lt;br /&amp;gt;
      &amp;lt;Button
        className="k-button"
        onClick={() =&amp;gt; {
          if (pdfExportComponent.current) {
            pdfExportComponent.current.save();
          }
        }}
      &amp;gt;
        Exportar en PDF
      &amp;lt;/Button&amp;gt;
    &amp;lt;/&amp;gt;
  );
};
export default BlankPage;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>react</category>
    </item>
    <item>
      <title>Download more than 1 PDF</title>
      <dc:creator>Jose Moreno Gomez</dc:creator>
      <pubDate>Mon, 25 Oct 2021 16:14:55 +0000</pubDate>
      <link>https://dev.to/josemgux/download-more-than-1-pdf-4382</link>
      <guid>https://dev.to/josemgux/download-more-than-1-pdf-4382</guid>
      <description>&lt;p&gt;I make a query to an api where I bring 1 json. The data from that json I pass to the table in jsx using Hooks.&lt;/p&gt;

&lt;p&gt;When I press the button with the exportPDF function it converts the html table to a PDF file.&lt;/p&gt;

&lt;p&gt;For now that's fine but it's only 1 record (ID) &lt;strong&gt;idMerchant::27675&lt;/strong&gt; How do I do if I want to bring 2 or more records, or how do I get 1 pdf of each record to be downloaded?&lt;strong&gt;idMerchant$in28::4193&lt;/strong&gt; (With this syntax I bring registers 28 and 4193) I can do it like this or in the way that I can solve it.For example: Try to create an array with 2 IDs &lt;strong&gt;const arrayIDs = ['::28', '::4193']&lt;/strong&gt;;And go through them in a forEach and inside the forEach the axios request if I downloaded 2 pdfs but blank or if it was not blank, only pdfs with the last ID.&lt;/p&gt;

&lt;p&gt;Delete table because it is too large&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState, useEffect } from 'react';
import axios from 'axios';
import { Table, Button } from 'reactstrap';
import { savePDF } from '@progress/kendo-react-pdf';

const styles = {
  title: {
    textAlign: 'center',
    fontSize: '30px',
    fontWeight: 'bold',
  },
  subtitle: {
    textAlign: 'center',
    background: '#67B71F',
    color: 'white',
  },
  td: {
    fontSize: '15px',
  },
  th: {
    fontSize: '15px',
    fontWeight: 'bold',
  },
  button: {
    fontWeight: 'bold',
  },
};
const options = {
  headers: {
    Authorization: process.env.REACT_APP_GETTOKENPDF,
  },
};

const BlankPage = () =&amp;gt; {
  const [legalName, setLegalName] = useState('');
  const [merchantName, setMechantName] = useState('');
  const [Id, setId] = useState('');
  const [officerUpdate, setofficerUpdate] = useState('');
  const [activationDate, setActivationDate] = useState('');
  const [merchantType, setMerchantType] = useState('');
  const [email, setEmail] = useState('');
  const [address, setAddress] = useState('');
  const [phone, setPhone] = useState('');
  const [ruc, setRuc] = useState('');
  const [legalRp, setLegalRp] = useState('');
  const [legalTypeId, setLegalTypeId] = useState('');
  const [legalIdNum, setLegalIdNum] = useState('');
  const [legalRepCountry, setLegalRepCountry] = useState('');
  const [NoMCC, setNoMCC] = useState(0);
  const [domain, setDomain] = useState('');
  const [socialRed, setSocialRed] = useState('');
  const [activity, setActivity] = useState('');

  const arrayIDs = ['::28', '::4193'];
  // const cantidad = arrayIDs.length;

  const exportPDF = () =&amp;gt; {
    const element = document.getElementById('content');
    savePDF(element, {
      fileName: `Informe de registro-${legalName}.pdf`,
      paperSize: 'A4',
      scale: 0.8,
      keepTogether: '.card',
    });
  };


  useEffect(() =&amp;gt; {
    const apiURL = `${process.env.REACT_APP_URL_PDF}?filter=idMerchant::27675`;
// const apiURL = `${process.env.REACT_APP_URL_PDF}?conditional=idMerchant$in28::4193`;

    axios
      .get(`${apiURL}`, options)

      .then(({ data }) =&amp;gt; {
        data.data.forEach((response) =&amp;gt; {
          setActivity(response.about);
          setLegalName(response.legalName);
          setMechantName(response.merchantName);
          setId(response.idMerchant);
          setofficerUpdate(response.officerUpdate);
          setActivationDate(response.activationDate);
          setMerchantType(response.merchantType);
          setEmail(response.email);
          setAddress(response.address);
          setPhone(response.phone);
          setRuc(response.ruc);
          setLegalRp(response.legalRep);
          setLegalTypeId(response.legalRepIdType);
          setLegalIdNum(response.legalrepIdNum);
          setLegalRepCountry(response.legalRepCountry);
          setNoMCC(response.mcc);
          setDomain(response.additionalAttributes.webPage);
          setSocialRed(response.additionalAttributes.redSocial);
        });
      })
      .catch((error) =&amp;gt; {
        // eslint-disable-next-line no-alert
        console.log('Alerta error: ', error.data);
      });
  }, []);


  return (
    &amp;lt;&amp;gt;
      &amp;lt;div id="content" className="card text-left "&amp;gt;
        &amp;lt;caption style={styles.title}&amp;gt;INFORMACION DE REGISTRO&amp;lt;/caption&amp;gt;
        &amp;lt;Table className="table table-bordered"&amp;gt;
          ...
        &amp;lt;/Table&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;br /&amp;gt;
      &amp;lt;Button color="info" size="lg" style={styles.button} onClick={exportPDF}&amp;gt;
        Download
      &amp;lt;/Button&amp;gt;
      &amp;lt;br /&amp;gt;
    &amp;lt;/&amp;gt;
  );
};

export default BlankPage;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>code</title>
      <dc:creator>Jose Moreno Gomez</dc:creator>
      <pubDate>Wed, 20 Oct 2021 21:56:31 +0000</pubDate>
      <link>https://dev.to/josemgux/code-2gmk</link>
      <guid>https://dev.to/josemgux/code-2gmk</guid>
      <description>&lt;p&gt;import logo from "./logo.svg";&lt;br&gt;
import "./App.css";&lt;br&gt;
import React from "react";&lt;br&gt;
import { Document, Page, Text, View, StyleSheet } from "@react-pdf/renderer";&lt;/p&gt;

&lt;p&gt;// Create styles&lt;br&gt;
const styles = StyleSheet.create({&lt;br&gt;
  page: {&lt;br&gt;
    flexDirection: "row",&lt;br&gt;
    backgroundColor: "#E4E4E4",&lt;br&gt;
  },&lt;br&gt;
  section: {&lt;br&gt;
    margin: 10,&lt;br&gt;
    padding: 10,&lt;br&gt;
    flexGrow: 1,&lt;br&gt;
  },&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;// Create Document Component&lt;br&gt;
const MyDocument = () =&amp;gt; (&lt;br&gt;
  &lt;br&gt;
    &lt;br&gt;
      &lt;br&gt;
        Section #1&lt;br&gt;
      &lt;br&gt;
      &lt;br&gt;
        Section #2&lt;br&gt;
      &lt;br&gt;
    &lt;br&gt;
  &lt;br&gt;
);&lt;/p&gt;

&lt;p&gt;export default MyDocument;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Render HTML in a component made with @react-pdf/renderer</title>
      <dc:creator>Jose Moreno Gomez</dc:creator>
      <pubDate>Wed, 20 Oct 2021 21:47:13 +0000</pubDate>
      <link>https://dev.to/josemgux/render-html-in-a-component-made-with-react-pdfrenderer-245p</link>
      <guid>https://dev.to/josemgux/render-html-in-a-component-made-with-react-pdfrenderer-245p</guid>
      <description>&lt;p&gt;A component made with react-pdf in case it does not support html then I want to create a table with data but that is made with react-pdf and I do not know how to do it.&lt;br&gt;
This is the example in npm =&amp;gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5qzN_vE4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uwqd3hz4p1bklyyn5lsa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5qzN_vE4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uwqd3hz4p1bklyyn5lsa.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
    </item>
  </channel>
</rss>
