Only apply the z-index style in React rendering when it is specifically set to zero

My goal is to set a dynamic z-index for my components based on the state variables. Currently, it only works when the zindex is set to 0.

Here is an example of my array:

images:[
                                    ['img1',false,[1,2,3],1,0],//4th one is zindex
                                    ['img2',false,[2,3,1],2,0],
                                    ['img3',false,[4,5],3,10],
                                    ['img4',false,[1,2,3],4,0],
                                    ['img5',false,[2,3,1],5,0],
                                    ['img6',false,[5],6,0],
                                    ['img7',false,[1,2,3],7,0],
                                    ['img8',false,[2,3,1],8,0],
                                    ['img9',false,[5],9,0],
                                    ['img10',false,[1,2,3],10,0],
                                    ['img11',false,[2],11,10],
                                    ['img12',false,[5],12,10]
                              ],

This is a snippet of JSX code:

{this.state.images.map((im,index) =>
                                    <div className="img-block" style={{'z-index':im[4]}}  draggable="true" onDragStart={this.drag.bind(this,im[3],index)} onDrop={this.drop.bind(this,im[3],index)} onDragOver={this.allowDrop}>
)}

When rendered in HTML, the output looks like this:

<div class="img-block" draggable="true" style="z-index: 0;">
<div class="img-block" draggable="true" style="z-index: 0;">
<div class="img-block" draggable="true"> //not rendered 10
<div class="img-block" draggable="true" style="z-index: 0;">
<div class="img-block" draggable="true" style="z-index: 0;">
<div class="img-block" draggable="true" style="z-index: 0;">
<div class="img-block" draggable="true" style="z-index: 0;">
<div class="img-block" draggable="true" style="z-index: 0;">
<div class="img-block" draggable="true" style="z-index: 0;">
<div class="img-block" draggable="true" style="z-index: 0;">
<div class="img-block" draggable="true" > //not rendered 10
<div class="img-block" draggable="true" > //not rendered 10

If you have any insights on what I might have missed here, please let me know.

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

In Internet Explorer 7, a newline within a <pre> tag may cause display issues

Within my ASP.NET MVC 3 project, I am working with the following code: <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" ty ...

Include a <div> element to display the date in an HTML format, ensuring that the days and months

I am working on a project where I have a list of dates and I need to format them by adding div tags to separate the days, months, and years into different divisions. <div class="campaign">30/11/2016 - <a href="#" target="_blank">Dummy Text& ...

Using jQuery to Validate Input Text Control Depending on Radio Selection

How can I ensure that the input text linked to the selected radio option is filled in? For instance, in the example above: If Contact 1's Email radio option is chosen, the Email text field for Contact 1 must not be empty, while the Phone and US Mai ...

Reveal Visual Content upon Hovering

Is there a way to show an image only when the mouse hovers over it? Additionally, can we underline the adjacent text at the same time? If the mouse moves away from the image, I'd like it to hide again and revert the text back to its original state. T ...

Steps for storing div content (image) on server

Currently in the process of developing a web application that allows users to crop images. The goal is for users to have the ability to email the URL so others can view the cropped image, ensuring that the URL remains active indefinitely by storing every c ...

Creating dynamic DIVs that adjust fluidly to different screen

I have a section containing 4 centered divs. Here is what I want to achieve: When the screen width is over 1280px, display all 4 divs in a row. When the screen width is less than 1280px, show 2 divs per row. And when the screen width is under 640px, disp ...

ReactJS presents an issue where buttons on the navigation bar are not properly aligned

I am currently utilizing the navbar component from Bootstrap 5, and I've encountered a UI problem. What is my current setup? This is the existing structure of my navbar: https://i.sstatic.net/eETzd.png What is my desired outcome? I aim to have the n ...

Customize React Bootstrap Slider Attributes on the Fly

Is it possible to dynamically set attributes for the React Bootstrap Slider control available at https://github.com/brownieboy/react-bootstrap-slider? For instance, can the control be disabled after the slideStop event? ...

How to utilize Enzyme to call a React prop in TypeScript

I'm currently in the process of converting my Jest tests from Enzyme to TypeScript, and I've come across a specific case that I'm unsure how to resolve. Essentially, I'm attempting to invoke a function passed as a prop to a sub-componen ...

What steps can be taken to avoid the div sidebar overlapping with the content on the

I am currently facing an issue with my website where the div sidebar scrolls with the page and overlaps the page content whenever the window is resized. To see a demonstration of the problem, you can visit this link: Below is the CSS code for the menubar ...

Code snippet causing element block JavaScript malfunction

I'm attempting to create a basic automatic slideshow using JavaScript. let currentIndex = 0; startSlideshow(); function startSlideshow() { let slides = document.getElementsByClassName("slide"); for (let i = 0; i < slides.length; i++) { ...

What's the best way to make sure a div container fills in the remaining space between elements?

How can I make the center div take up the remaining space between the left and right divs, without covering them? The contents in the center can overflow hidden if necessary. View my code on jsFiddle HTML <div id=container> <div id=left> ...

Tips for resolving package conflicts while integrating Wagmi View into a React/Typescript application

I am facing an issue while attempting to incorporate wagmi and viem packages into my project. Currently, my project utilizes the react-scripts package with the latest version being 5.0.1, and Typescript is operating on version 4.9.5. However, upon trying ...

Is there a way to display two cards side by side in mobile view?

On a desktop view, 2 cards are displayed in a row. I would like them to also appear in a row on mobile view. I tried using col-sm-4 but it's not working. How can I get the cards to display in a row on mobile view so that I can see both the product pho ...

Exploring the integration of Javascript and PHP variables for seamless data interchange

Answering My Own Question I had a situation where I needed to use AJAX to retrieve a video from Youtube, but it required the use of a PHP file in conjunction with Javascript variables. Unfortunately, I couldn't figure out how to do it on this platfor ...

Is it necessary to reload the page each time to see updates on the navbar in nextjs?

I recently developed a Next.js application with a Navbar component integrated into my layout.tsx file. The challenge arises when a user logs in and is redirected to the home page, which showcases a link in the Navbar for viewing their profile. However, I n ...

Upgrading may lead to errors if react-dom is imported without being used

After recently updating react-dom to version 16.5.2, my tests have started to fail with the error message: requirejs error occurred TypeError: Cannot read property 'unstable_cancelScheduledWork' of undefined. Despite checking the release notes a ...

Create JSON data in JavaScript for nivo using an array or a function

I have been attempting to generate a sine wave plot using Nivo, but I am struggling with the required data format. The desired output should follow this structure: {{x:1,y:1},{x:2,y:4},{x:3,y:8},....} Nivo specifies the following data format: dataobject[] ...

What is the most effective method for incorporating access token authentication in a React application?

As a newcomer to React, I am working on implementing authentication using Express.js in my react web application. I have successfully set the token in response cookies on the backend with the HttpOnly flag, but unfortunately, I am unable to read it on the ...

Tips for implementing a Dialog Box within a Card Action Button Group

I'm currently exploring the option of incorporating a Dialog box as a button within a Button Group, which is then nested inside a CardActions component in Material UI. Previously, I had success with using regular Buttons instead of a Dialog, where th ...