So I would like to iterate over some props that are being passed to my react component and build a dynamic set of html elements based on the number of links that are passed by the props. the example below will just render the first link.
import React from "react";
import ReactDOM from "react-dom";
const Links = (props) => {
return (
<div>
<p>{props.link.link1}</p>
</div>
)
}
export default Links;
i'm having trouble working out how to map the incoming props to generate a p tag for every link that is in the props object. the links are pulled from a larger json object and are passed to the above component as props.
"links": {
"link1": "https://www.google.com",
"link2": "https://www.google.com",
"link3": "https://www.google.com",
"link4": "https://www.google.com",
"link5": "https://www.google.com",
"link6": "https://www.google.com"
}
I've tried something like the below but just can't get it work. do i need to make my react component class based? and introduce a constructor / render method to do this correctly?
const buildLinks = this.props.data.map(release => {
render (
/// p tags + props go here
)
})