Nested Blocks in React Components

I am attempting to create a layout that includes text, a line, and a button similar to the design in this image: https://i.sstatic.net/RgGFU.png Although my code functions correctly, the CSS styling is not quite right:

{ retrospectives.size > 0 &&
  <div className='c-division-line u-margin-bottom'>
    <h3>
      <span> Last Retrospectives </span>
    </h3>
  </div>
}
{ retrospectives.size > 4 &&
  <div className="c-division-line__button u-font-size--12px">
    <RetroLink project={projectId} path={path}/>
  </div>
}

However, when I attempt to nest one block of code within another for correct CSS styling, the functionality breaks. How can I achieve both proper CSS and functioning code?

{ retrospectives.size > 0 &&
  <div className='c-division-line u-margin-bottom'>
    <h3>
      <span> Last Retrospectives </span>
    </h3>
    { retrospectives.size > 4 &&
      <div className="c-division-line__button u-font-size--12px">
        <RetroLink project={projectId} path={path}/>
      </div>
    }
  </div>
}

I considered creating a separate function, but it did not yield the desired results:

  buttonLink () {
    const { retrospectives, projectId, path } = this.props
    if (retrospectives.size > 4) {
      return <div className="c-division-line__button u-font-size--12px">
        <RetroLink project={projectId} path={path}/>
      </div>
    }
  }

And calling it like this {this.buttonLink()}

Answer №1

One suggestion is to assign your button element to a variable for easier handling:

const displayButton = retrospectives.size > 4 && (
     <div className="c-division-line__button u-font-size--12px">
         <RetroLink project={projectId} path={path}/>
     </div>
);

return retrospectives.size > 0 && (
     <div className='c-division-line u-margin-bottom'>
         <h3>
             <span> Last Retrospectives </span>
         </h3>
         { displayButton }
     </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

Making a JavaScript script compatible with select drop down menus that can handle multiple selections

After searching through various sources, I came across two threads that address my question regarding the code to use. Despite finding solutions, I am struggling to understand how to implement the script. My limited experience with JavaScript is likely cau ...

What is causing the dysfunction of angular2 form when used with the HTML <form> tag?

Can someone explain the strange behavior of the <form> element in ng2 to me? I have noticed something odd and need some clarification :) To demonstrate, I have created a simple Plunker example at this link: https://plnkr.co/edit/vdrHJBNdd26y6YhPXTHD ...

Tips for including numerous hyperlinks in a single row for a website's navigation menu

I need assistance in creating a navigation bar for my website that includes multiple headers with links. I am not sure if the issue lies within my CSS, HTML, or both. Can someone please help me troubleshoot? index.html <!DOCTYPE html> <html> ...

Encountering difficulties when attempting to upload to Google Cloud using a signed URL

Seeking help to troubleshoot why the video upload is not working as expected. I am able to successfully connect to my bucket using a signedURL, but when trying to upload the video, it's not functioning properly. const submitVideo = async () => { ...

When employing the .map() function in JavaScript, you can iterate through arrays containing both primitive types and objects

When using the .map() method to iterate over an array, changes made to individual elements will affect the array if the elements are objects, but not if they are simple values like booleans. For example, if the array is [true, false] and we use .map() to s ...

Troubleshooting the issue: JavaScript's Time comparison failure with JSON versus Local time

Dealing with JSON data like the following: [ { "hourly_AQI": 73.0, "hourly_date": "Tue, 31 Oct 2023 11:00:00 GMT" }, { "hourly_AQI": 79.0, "hourly_date": "Tu ...

Validating React on multiple checkbox fields

Could someone please provide me with an example of how to validate multiple checkboxes in a React application? I have a series of questions, each with its own checkbox. Once all the checkboxes are checked, I need to activate a continue button. I know how ...

Strings holding special arrangements of breaks in between

Currently, I am developing a portal that enables examiners to provide a problem statement, sample input, and sample output. However, I am facing an issue where the sample input/output values are stored as complete strings, causing line breaks to not render ...

Unable to loop through the Array

let Users = [ { name: 'John', id: '1', jp: 'USA' }, { name: 'Jane', id: '2', jp: 'Japan' }, ]; export function DisplayUsers(usersList) { return ( <div> {usersList?.map((user ...

JavaScript is utilized to implement the k-means clustering algorithm, which demonstrates convergence yet lacks stability in its

Although I understand the concept of convergence, I am puzzled by the fact that the results vary each time the algorithm is refreshed, even when using the same dataset. Can someone point out where my methodology might be incorrect? I've been strugglin ...

The React component is displaying a video, however the stream is not being passed through any methods

Currently, I have a React component that is supposed to display predictions in the form of bounding boxes. The video is displaying properly on the page for the component, but unfortunately, there are no bounding boxes being shown; when I check the output, ...

The Omniture dashboard is displaying an incorrect URL in My Reports

I am currently exploring the possibility of integrating Omniture into my website. I have received some JavaScript code, but I am unsure whether I should include it on the page or simply add additional parameters to the s object properties. When viewing t ...

Angular can help you easily convert numbers into a money format

I need assistance in converting a number to Indian currency format. Currently, I have attempted the following: http://plnkr.co/edit/lVJGXyuX0BMvB9QUL5zS?p=preview function formatMoney(credits) { console.log(credits+'credits'); var last ...

Problem with Jquery fetching data from specified div not resolved

Here is a working example: var myvar; $.get('formElements.html', function(data) { myvar = data; }); However, this code does not work as intended: var myvar; $.get('formElements.html .className', function(data) { myvar = data; } ...

My React application came to an unexpected halt with an error message stating: "TypeError: Cannot read properties of undefined (reading 'prototype')"

Everything was running smoothly with my app until I encountered this error without making any significant changes: TypeError: Cannot read properties of undefined (reading 'prototype') (anonymous function) .../client/node_modules/express/lib/resp ...

Linking a radio button to another mirrored radio button for selection

It should be a straightforward task. I have two sets of radio buttons that mirror each other, known as set A and set B Set A includes buttons 1, 2, and 3 Set B also consists of buttons 1, 2, and 3 The desired behavior is for clicking button 1 in set A t ...

Creating an image that scales to full width within a Bootstrap column after switching to mobile view

I am having trouble getting the image on the right to expand to full width when the screen size is reduced, transitioning it to mobile view. Is there a Bootstrap class that works similarly to "img-fluid", but displays the image in full width below the text ...

Refreshing ng-model within a radio input

Currently, I am utilizing a jQuery library for radio/checkbox components. Although I am aware that combining jQuery with Angular is not ideal, the decision to use this particular library was out of my control and cannot be altered. One issue I have encount ...

Discover how to reveal a hidden div tag upon hovering over a different div tag using CSS

I have a minor issue that I need help with. I want to achieve an effect where one div is displayed when another div is hovered over in CSS. Once the cursor is removed, the second div should be hidden again. How can I accomplish this? There is a second hid ...

Is it possible to display the bounding box of an object in Threejs?

Originating from Ogre and C++, I have now transitioned to developing with Threejs. When working with Ogre, for debugging purposes, I frequently utilize the following method: Ogre::SceneNode* n = ... n->showBoundingBox(true); This method is simply use ...