<?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>Forem: Nicholas Wilson</title>
    <description>The latest articles on Forem by Nicholas Wilson (@njdevelopment).</description>
    <link>https://forem.com/njdevelopment</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%2F394588%2F172dd751-797d-4a43-939b-375440bab65d.png</url>
      <title>Forem: Nicholas Wilson</title>
      <link>https://forem.com/njdevelopment</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/njdevelopment"/>
    <language>en</language>
    <item>
      <title>Help with React .map through JSON data.</title>
      <dc:creator>Nicholas Wilson</dc:creator>
      <pubDate>Mon, 25 May 2020 02:08:42 +0000</pubDate>
      <link>https://forem.com/njdevelopment/help-with-react-map-through-json-data-beh</link>
      <guid>https://forem.com/njdevelopment/help-with-react-map-through-json-data-beh</guid>
      <description>&lt;p&gt;I just signed up here to get some help as i'm new to react and this is where reactjs.org suggested i go for help, and i'm not sure if this is the right place to ask questions about code but I have an issue that I can't seem to figure out. &lt;/p&gt;

&lt;p&gt;I have a .json file in one of my directories and i've imported it into one of my .js files. &lt;/p&gt;

&lt;p&gt;I'm trying to set the state to the .json file which i've done successfully. However, I can't figure out how to map through the data and display it in my render method properly. &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//other react imports
import data from '../data/portfolio.json';

class Portfolio extends React.Component {
    constructor(props) {
        super(props);
        this.state = {data}
    }

    render() {     
        return(
            &amp;lt;div&amp;gt;
                &amp;lt;a href={this.state.data.portfolio[0].url}&amp;gt;
                   &amp;lt;img className="img-fluid" 
                        src={this.state.data.portfolio[0].image} 
                        alt={this.state.data.portfolio[0].site} /&amp;gt;
                   &amp;lt;p&amp;gt;{this.state.data.portfolio[0].site}&amp;lt;/p&amp;gt;
                &amp;lt;/a&amp;gt;
            &amp;lt;/div&amp;gt;
        )
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This works fine, but I want to avoid having to create multiple anchor, image and paragraph tags and loop through to display everything. Any suggestions or places I can go to read how to do this with a local .json file? I tried this...&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myData = this.state.data;
const listItems = myData.map((myData) =&amp;gt;
  &amp;lt;li&amp;gt;{myData}&amp;lt;/li&amp;gt;
);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This doesn't work though because I think .map is used for arrays online. Should I use a for loop or something else?&lt;/p&gt;

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