Utilizing React's Conditional Rendering Alongside Bootstrap to Maintain the Layout Intact

I'm currently developing a project using React and Bootstrap that involves incorporating a large bar graph with two smaller boxes, all positioned horizontally together.

To visualize how it should appear, please expand the pen window to see them arranged side by side correctly:

https://codesandbox.io/s/lO9rvrBYM

However, I am encountering challenges with conditional rendering logic when there is no data and I need to avoid displaying the big bar graph. To explore this issue further, click on the following link:

https://codesandbox.io/s/ELLzLo3g

In the scenario involving conditional rendering, the elements are not properly positioned and end up stacked on top of one another permanently.

It seems like the problem may be related to line 69. I believe that modifying the rendering of the graph by removing one extra closing </div> could help maintain the horizontal layout, but this modification leads to a syntax error.

If anyone with expertise in Bootstrap has any advice or tips on resolving this issue, your input would be greatly appreciated.

Answer №1

Initially, the clarity of your question and examples is a bit lacking, so there may be some misunderstanding in my response :)

Your goal seems to involve creating a 2-column layout with conditional display for one of the columns.

The layout structure will be managed by bootstrap (although there are some errors in your column setup), while the conditional display should be controlled through the component's state.

To start, your layout should resemble the following:

<div className='row'>
    <div className='col-sm-7'>
        <div> [insert your chart here] </div>
    </div>
    <div className='col-sm-5'>
        <div> [insert your first block here] </div>
        <div> [insert your second block here] </div>
    </div>
</div>

Next, you'll need a boolean value in the component's state to determine whether the chart should be displayed. Let's assume this information is stored in this.state.showChart

<div className='row'>
    {this.state.showChart ?
        <div className='col-sm-7'>
            <div> [insert your chart here] </div>
        </div>
    : '' }
    <div className='col-sm-5'>
        <div> [insert your first block here] </div>
        <div> [insert your second block here] </div>
    </div>
</div>

If more clarification is needed, feel free to provide additional details or samples, and I can assist further directly on your sandbox environment :)

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

Exploring tabs functionality with Material UI, Jest, and Enzyme testing

I am currently testing a component with tabs. My initial test is to verify the correct initial state, followed by testing whether clicking on another tab changes the state. The technologies I am using for this are material-ui, jest, and enzyme. import Rea ...

Currently, my focus is on creating a robust slash command handler for discord.js version 13

I've been attempting to update my command handler to support slash commands, but I keep encountering an Invalid Form Body error when trying to activate the bot. I'm hesitant to switch handlers since I use this one for all my bots, but I can&apos ...

What is the best way to maintain the index of a for loop when incorporating AJAX to insert PHP data into an object?

Hey there, I'm diving into the world of AJAX and PHP implementation. I've hit a bit of a roadblock lately as I feel like I might be missing a simple solution. Currently, my code fetches data from a trove API using PHP, and for each item it appen ...

Expanding parent nodes in Jstree to load child nodes dynamically (json)

I am trying to optimize the performance by loading the child nodes of a parent node only after clicking on that specific parent node. It is important because there are many child nodes, so this method helps in keeping the performance high. Currently, I ha ...

A guide on incorporating java.type into your JavaScript code

I've been attempting to utilize the following command in my JavaScript: var file = new Java.type("java.io.File"); Unfortunately, I'm encountering an error: Uncaught ReferenceError: Java is not defined Can anyone provide guidance on how to suc ...

Organizing a Vue.js SPA project: Implementing Vuex store and API calls efficiently

Here is how I have organized the structure of my Vue app: components/ article/ AppList.vue common/ AppObserver.vue NoSSR.vue layout/ AppFooter.vue AppHeader.vue ui/ AppButton. ...

Error encountered: Multer does not recognize the field when attempting to upload multiple files in a node.js environment

I would like to upload two files in one request using Node.js and I am utilizing multer for this task. Here is my request in Postman: https://i.sstatic.net/8ZEno.png Additionally, I am using multer in routing: router.post( "/Create", Uploa ...

Illuminate specific areas of a mapped image upon hovering over text on a webpage

Scenario: There is an image on the page with various mapped areas. A list of text elements is also present on the page. Desired functionality: Hovering over different text items in the list should result in highlighting corresponding areas on the mappe ...

When incorporating conditional statements into your code, make sure to utilize the tags <script> along with

I have some script tags as shown below: <script src="cordova-2.5.0.js"></script> <script src="js/jquery-1.7.2.min.js"></script> <script src="js/jquery.mobile-1.1.1.min.js"></script> <script src="js/jquery.xdomainajax ...

Creating an interactive dropdown menu in React JS on click

My goal is to display a select tag when a text or div element is clicked. I'm unsure of the correct method and location to render it. Therefore, I decided to create a handler function that sets a variable, isItClick, to true in order to show the sele ...

Tips for relocating anchor elements to less desirable locations

My website has an issue with anchor elements appearing too frequently and not in the desired location. I need someone to help fix this so there are only two anchors displayed. After checking my code, it seems like there are not more than the specified num ...

How come the CSS for my angular ngx-mat-datetime-picker and mat-datepicker collide when they are both present on the same page?

Within the same form, I have two input fields stacked under each other. One is an ngx-mat-datetime-picker and the other is a mat-datepicker. Individually, they function correctly. However, when I open them for the second time, the one I opened first appear ...

Mobile Bootstrap4 NavBar Bug Fix

I am currently working on coding a website with Bootstrap. The navbar functions perfectly on desktop, but when accessed via mobile device, the button containing all the links does not work. Here is a picture for a more accurate description Below is my HTM ...

Javascript: triggering a self-executing function manually

I have a code snippet similar to the following: var msg="first call"; (function test(msg) { console.log("inside self call"); } )(); msg="second call"; console.log("before inline call"); test(msg); console.log("after inline call"); In thi ...

What steps are required to establish a PHP development and production environment?

I find myself in the position of taking over a small PHP site that relies on a database. While I'm well-versed in C# programming and have experience with databases and web design, I am quite unfamiliar with PHP. My boss wants me to establish both a s ...

Creating a dynamic overlapping image effect with CSS and JavaScript

My fullwidth div has an image that overlaps it. When the browser is resized, more of the image is either shown or hidden without resizing the actual image itself. I managed to get this effect for the width, but how can I achieve the same result for the hei ...

Using Vue.js to showcase real-time Pusher data in Laravel 5.4

I am currently working on developing a real-time chat application using vue.js, Pusher, and Laravel. I have successfully managed to receive information from Pusher, as I can view the JSON data in the console with the correct details. However, I am facing a ...

Exploring methods to conduct testing on an AngularJS application using AngularJS end-to-end testing, specifically focusing on scenarios involving multiple inputs

Our program includes a directive that is repeated multiple times with an input field. The structure of our code resembles the following: <li> <label>AMI</label> <div class="searchbox" searchbox="" filter="search.ami"> ...

Convert PHP function output to HTML element

Check out the content of my Class.php file: <?php class Class { public function validate() { if(empty($_POST['first_name'])) { return 'first name should not be empty!'; } elseif(em ...

What is causing the failure of success function commands to be executed?

Currently, I am facing some inconsistencies between my locally hosted app on WAMP (working perfectly) and the deployed version of my app. In an attempt to resolve this issue, I am working with CodeIgniter and jQuery AJAX. As part of my troubleshooting proc ...