Cannot render <Image> inside <Section> component

As a beginner in React, I am attempting to create an app following a tutorial. In my component, I utilized the figure tag but it's not showing up when inspecting element in Chrome. Here are the code snippets:

The tutorial includes a div tag as a child of the container. However, I can't seem to achieve that.

View the image from the tutorial showcasing the div tag with a figure tag as a child element

Here is my code which only contains a div tag

index.js

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Main from './Components/Main'
import './styles/stylesheet.css'

ReactDOM.render(<Main/>, document.getElementById('root'));

ReactDOM.render(, document.getElementById('root'));

Main.js

import React, { Component } from 'react'
import Title from './Title'
import Photowall from './Photowall'
const posts = [{
id: "0",
description: "beautiful landscape",
imageLink: "https://image.jimcdn.com/app/cms/image/transf/none/path/sa6549607c78f5c11/image/i4eeacaa2dbf12d6d/version/1490299332/most-beautiful-landscapes-in-europe-lofoten-european-best-destinations-copyright-iakov-kalinin.jpg" +
"3919321_1443393332_n.jpg"
},

{
id: "1",
 description: "Aliens???", imageLink: "https://s3.india.com/wp-content/uploads/2017/12/rocket.jpg"
}, 

{
id: "2",
 description: "On a vacation!",imageLink: "https://fm.cnbc.com/applications/cnbc.com/resources/img/editorial/2017/08/24/104670887-VacationExplainsTHUMBWEB.1910x1000.jpg"
}

class Main extends Component{
render(){
return <div>
          <Title title={'Photowall'}/>
          <Photowall posts={posts}/>
        </div>
}

}
export default Main

Photowall.js

import React,{ Component} from 'react'
import Photo from './Photo'
class Photowall extends Component{
render() {
return

    <div className='photo-grid'>
        {this.props.posts.map((post,index)=> <Photo key={index} post={post}/>)}
    </div>

  }
  }
export default Photowall

Photo.js

import React, {Component} from "react";

class Photo extends Component{
render(){
const post =this.props.post
return <figure className="figure"></figure>

}
}
export default Photo

Stylesheet.js

html{
font-size: 10px;
}
h1{
font-family: billabong;
text-align: center;
font-size: 13rem;
margin: 2rem 0rem;
font-weight: 400;
letter-spacing: 4px;
color: grey;
}

@font-face {
font-family: billabong;
src: url('https://fonts.cdnfonts.com/s/13949/Billabong.woff') format('woff');
}
.photo-grid {
max-width: 1000px;
margin: 0 auto;
display: flex;
flex-wrap: wrap;
} 

.figure {
flex-basis: calc (33.333%-4rem);
border: 1px solid #d3d3d3;
padding: 2rem;
flex-grow: 1;
margin: 0 2rem;   
}

Answer №1

Your Photowall HTML is unresponsive

It appears that your entire Photowall component is failing to display.

The issue lies in the fact that your HTML code is not positioned directly after the return statement (resulting in unresponsive code).

If you place your HTML below the return, it's as if you are returning undefined and therefore the component won't render anything.


Remember to always position your initial HTML line immediately following the return, without any extra lines in between.

class Photowall extends Component{
  render() {
    return <div className='photo-grid'>
          {this.props.posts.map((post,index)=> <Photo key={index} post={post}/>)}
       </div>
  }
}

Alternatively, you can enclose your HTML within brackets for better readability:

class Photowall extends Component{
  render() {
    return ( // starting from the same line as return
       <div className='photo-grid'>
          {this.props.posts.map((post,index)=> <Photo key={index} post={post}/>)}
       </div>
   )
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Uncovering the array within Javascript

I'm struggling to figure out why I can't access an array that PHP sends back to me. When AJAX makes a call, I send back this: $response['success'] = true; In my PHP file, I use echo json_encode($response); to send it. However, when I ...

What steps can be taken to ensure authenticated requests are made to Google Cloud Storage from a NextJS app?

Utilizing a Cloud Storage instance to store images on my NextJS web app has been presenting some challenges. The way I reference the images is as follows: ... some code image="https://storage.cloud.google.com/{my-project}/myimage.jpg" ... some m ...

Adjust top position dynamically during resizing

When resizing the window, I am facing an issue with the image going outside of the box. I believe adjusting the position top of the image based on the box height might help in fitting the image properly within the box. $(window).resize(function() { va ...

Converting a JavaScript string into an array or dictionary

Is there a way to transform the following string: "{u'value': {u'username': u'testeuser', u'status': 1, u'firstName': u'a', u'lastName': u'a', u'gender': u'a&a ...

Looking for assistance on how to use Express JS to make a post request to insert data with an array of objects into a database. Can anyone provide guidance?

While utilizing ExpressJS for serverside functionality, I encountered an issue when making a post call with multiple objects in an array. The error message displayed is as follows: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to t ...

Implementing OAuth with React and Redux while keeping the session secure

What is the recommended way to authenticate with OAuth2 in React while utilizing Redux? In my current setup, I am using Redux-Auth-Wrapper to wrap react-router components. If the user is not authenticated, I dispatch an action that triggers a GET request ...

What is the best way to manage a significant volume of "business" data or objects within my JavaScript project?

I specialize in working with AngularJs and have a factory that provides services related to buildings. I am managing a large number of buildings (around 50-60) with multiple properties and sub-properties associated with each one (approximately 15-20, some ...

Expanding content to cover the entire width using CSS Bootstrap 5

As a newcomer to Bootstrap, I am working on customizing an existing Bootstrap example. My objective is to expand the width of the div tag (with id "inner") to fill the entire screen. I have experimented with various approaches, such as resetting the margi ...

Utilizing PHP Code within Inline CSS in HTML guides

Is it possible to integrate PHP code into Inline CSS? Here is an example: Check out this code snippet: <div class="col-auto"> <div class="h5 mb-0 mr-3 font-weight-bold text-gray-800">%22</div> </div> <div ...

Store the information in the user interface of React by converting it into a file format

Currently, I am retrieving data from an API and downloading a specific file. My goal is to store this same file in the public directory within my react application. https://i.sstatic.net/bS8Z4.png this.state = { fileDownloadUrl: null, fileName ...

Creating an Interactive Table Using HTML, JavaScript, and PHP?

After reviewing this project, I am looking to customize the js function in relation to my own table. The key focus is on the following code: $("#employee_table tr:last").after("<tr id='row"+$rowno+"'><td><input type='text&apo ...

Trying out the change event in react-final-form

Would anyone be able to guide me on how to properly test this straightforward behavior? I've been grappling with this issue for quite some time now, and I'm really hoping that it's just a small oversight on my part, as testing a change event ...

Discovering the most recent messages with AJAX

I'm feeling a bit lost on this topic. I'm looking to display the most recent messages stored in the database. (If the messages are not yet visible to the user) Is there a way to achieve this without constantly sending requests to the server? (I ...

Having trouble with my router in the express app - the .find and .findByID methods are not working properly. Also,

In my current setup with NextJS/MERN stack, I am using the server.js file in NextJS to import API routes and make API calls. The routes seem to be functioning properly as there is activity when calling them from Postman or the browser. However, it appears ...

Vue-router is failing to display child routes in the application

I have an object within the Vue router that specifies a path for books and their details. { path: "/books", name: "books", component: Books, children: [ { path: ":id", name: "books.detail", ...

How to send the value of a JavaScript loop variable to PHP using AJAX

How can I send variables in a loop to a PHP file using AJAX? var lat; var lng; var array = [22.399602, 114.041176, 22.344043, 114.0168, 22.327529, 114.087181]; console.log(array); for (var i = 0; i < 6; i += 2) { lat = array[i]; console.log("l ...

Utilize the Vue-Chartjs plugin registration for a specific chart component only

I am currently working with a chart component in Vue 3 using the composition API. My goal is to incorporate the datalabels plugin into this specific chart only. Upon attempting to register the plugin outside of the chart's data or options, I noticed ...

Creating a Vue component that leverages the computed property from a mixin

My situation involves a straightforward component that utilizes a mixin shared across various components that have similar functionalities. However, upon running it, an issue arises: The error message "Property or method 'activeClass' is not ...

retrieving a map containing the values from an array using the `.includes()`

Currently, I am attempting to map my routes based on the roles they possess. For example, my mapped routes may have roles like ["User", "Admin"] or just ["Admin"]. The current user can have one or multiple roles assigned to them. This particular function w ...

What is the best way to adjust a component to display varying content based on the scenario?

I am looking for a way to reuse a component on my website that displays messages. The challenge is that in one section, the content consists of only a title and paragraph, while in another section, there are multiple titles and content pieces. I have imple ...