The button component is unresponsive

An app was developed with a component containing signin and signup buttons on the right side. However, there is an issue where the Sign up button is not clickable. Below is the code snippet for the component =>

import React from "react";

export default function Abar() {

    const handleClick = () => {
        console.log("Eee");
    };

    const styles = {
        body: {
            margin: 0,
            fontFamily: "Arial, sans-serif"
        },
        flexContainer: {
            display: "flex",
            justifyContent: "space-between",
            alignItems: "center",
            padding: "10px 20px",
            backgroundColor: "black",
            color: "white"
        },
        skillSphereTitle: {
            fontSize: "24px"
        },
        buttonContainer: {
            display: "flex",
            gap: "10px"
        },
        button: {
            color: "white",
            border: "1px solid transparent",
            borderTop: "4px solid #0169AD",
            backgroundColor: "black",
            cursor: "pointer",
            padding: "10px 20px"
        }
    };

    return (
        <div style={styles.flexContainer}>
            <div>
                <h6 style={styles.skillSphereTitle}>
                    Skill Sphere
                </h6>
            </div>
            <div style={styles.buttonContainer}>
                <button
                    type="button"
                    style={styles.button}
                    onClick={() => console.log("Rohan")}
                >
                    Sign Up
                </button>
                <button
                    type="button"
                    style={styles.button}
                    onClick={() => console.log("Rohan")}
                >
                    Sign In
                </button>
            </div>
        </div>
    );
}

Attempted various solutions found online but none resolved the issue.

Answer №1

Your code appears to be accurate. It's possible that you are displaying the same message on both buttons, which may be causing confusion about whether it is functioning correctly.

Consider displaying different messages on each button to avoid any confusion.

<button
  type="button"
  style={styles.button}
  onClick={() => console.log("Sign up clicked")}
>
  Sign Up
</button>

Answer №2

Your code is functioning well, you can execute it right here on StackOverflow:

function Foo() {

            const handleClick = () => {
                console.log("Bar");
            };

            const styles = {
                container: {
                    margin: 0,
                    fontFamily: "Arial, sans-serif"
                },
                flexDiv: {
                    display: "flex",
                    justifyContent: "space-between",
                    alignItems: "center",
                    padding: "10px 20px",
                    backgroundColor: "black",
                    color: "white"
                },
                titleStyle: {
                    fontSize: "24px"
                },
                buttonContainer: {
                    display: "flex",
                    gap: "10px"
                },
                buttonStyle: {
                    color: "white",
                    border: "1px solid transparent",
                    borderTop: "4px solid #0169AD",
                    backgroundColor: "black",
                    cursor: "pointer",
                    padding: "10px 20px"
                }
            };

            return (
                 <div style={styles.flexDiv}>
                     <div>
                         <h6 style={styles.titleStyle}>
                             My Title
                         </h6>
                     </div>
                     <div style={styles.buttonContainer}>
                         <button
                             type="button"
                             style={styles.buttonStyle}
                             onClick={() => console.log("Click One")}
                         >
                             Button One
                         </button>
                         <button
                             type="button"
                             style={styles.buttonStyle}
                             onClick={() => console.log("Click Two")}
                         >
                             Button Two
                         </button>
                     </div>
                 </div>
             );
        }

        const rootElem = ReactDOM.createRoot(document.getElementById('root'));
        rootElem.render(<Foo/>);
<script src="https://cdn.jsdelivr.net/npm/react@18/umd/react.development.js"></script>
<script src="https://cdn.jsdelivr.net/npm/react-dom@18/umd/react-dom.development.js"></script>
<div id="root">Loading...</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

The issue with React Forward Ref not functioning properly has been identified specifically in conjunction with Custom Components

I am facing an issue where I cannot get the Material UI Tooltip to appear when wrapping my custom component. Despite using ForwardRefs correctly, the tooltip does not show up regardless of events like hover or click. const MyComp = ({ buttonRef }) => { ...

Personalize scrollbar appearance in Mozilla Firefox and Internet Explorer

When it comes to customizing the scrollbar in chrome, CSS makes it easy: ::-webkit-scrollbar { width: 7px; } Unfortunately, this method does not have the same result in Firefox (version 38) and IE (version 11). I attempted the following code as an alter ...

After upgrading to version 4.0.0 of typescript-eslint/parser, why is eslint having trouble recognizing JSX or certain react @types as undefined?"

In a large project built with ReactJs, the eslint rules are based on this specific eslint configuration: const DONT_WARN_CI = process.env.NODE_ENV === 'production' ? 0 : 1 module.exports = { ... After upgrading the library "@typescript-es ...

Next.js throwing an error: TypeError - attempting to read property 'map' of undefined

I am facing an issue with my Next Js project. I have implemented the backend logic to display data, but when I attempt to show all the data using the useEffect hook and the map function, I encounter the following error: TypeError: Cannot read property &apo ...

Displaying an array of objects in the MUI Datagrid interface

I have integrated Redux into my project to retrieve data from the API, and this is a snapshot of the data structure: https://i.stack.imgur.com/jMjUF.png My current challenge lies in finding an effective way to display the information stored within the &a ...

What is the best way to eliminate a specific value within a flatmap?

This is the flatMap: const choices = names.flatMap( (item) => item.name + " - " + item.size + "- " + item.category ); console.log(choices): https://i.stack.imgur.com/MO4b1.png If the item.category is equal to S-XL, how can ...

Show a distinct row from an API using React

I am attempting to create a map function to display all the items from the API Screenshot of code showing the items Here is the console log displaying the fetched items from the API I encountered an error with the map function not working. Any solutions ...

Encountering an error when attempting to generate a production build after running the npm install command with the

After adding the brotli-webpack-plugin as a devDependency, I encountered an issue when attempting to generate a production build using npm run build (which internally runs next build). The error message displayed was: Error: Cannot find module 'bro ...

What is the best way to utilize an onClick on a button to update a value that is being utilized in a useEffect hook?

I am looking for a way to dynamically change the content displayed in this section without navigating to another page. I have two sets of data - one displaying all blogs and the other showing only blogs authored by "mario". How can I implement a button cli ...

What is the process of incorporating npm packages into a .NET Core project within Visual Studio 2019?

As I venture into the world of front end development using React in conjunction with .NET Core for backend, I find myself grappling with new tools and technologies. My task is to utilize Visual Studio 2019 for working with .NET Core, a development enviro ...

Python - Selenium: A guide to locating elements based on color

I have a situation where I need to select only the "Claim" button from the first div, even though both div cases are very similar. Is using background color a good way to identify my element? Or do you have any other ideas? 1. <div class="well well-sm ...

Looking to adjust the positioning of text being inserted into a column - unable to utilize text-align or float properties

I'm struggling to position my text in a specific area within a column using CSS. Our app displays a price when a quantity is selected, but I can't seem to center the $14 under 'Item Total'. Even using float: center; hasn't worked f ...

Tips for creating a stylish, blurred, and centered box for a login form on a full-size background that is also responsive

I attempted to create a login form on an HTML page using Angular, featuring a full-size background image that is centered. The form itself is contained within a div with a blurred background, also centered both horizontally and vertically within the browse ...

Struggling to effectively use XPath to target LI elements that contain specific text

Below is the HTML code for the list item in question: <li class="disabled-result" data-option-array-index="1" style="">4" (0)</li> Here is my attempt at using JavaScript to hide this list item, but it's not working as expected: var xpat ...

Ways to customize the appearance of an iframe's content from a separate domain

I am facing a challenge with my widget and multiple websites. The widget is hosted on one domain, but the websites use an iframe to display it. Unfortunately, because of the Same Origin Policy, I cannot style the content of the iframe from the parent websi ...

Dynamic Selection of JSON Key-Value Pairs in React Framework

My json data structure resembles the following: { "index": 1, "ln": "27953", "name": "Product 1", "availability": { "day0726": "G", "day0727": "G", "day0728": "G", } } I am looking for a way to dynamically disp ...

Looking for a way to scroll images without relying on the marquee tag? Whether you prefer using JavaScript, jQuery,

<marquee> <div class="client"> <img src="images/c1.png"/> </div> <div class="client"> <img src="images/c2.png"/> </div> <div class="client"> ...

Issue with Website Rendering: Safari 4 exhibits display glitch showing temporary content before showing a blank white screen

Currently, I'm in the process of developing a specialized rails application. However, there seems to be an unusual rendering error that has been reported by Safari 4 users. It's quite peculiar because the page appears briefly but quickly disappea ...

How can we have a div stay at the top of the screen when scrolling down, but return to its original position when scrolling back up?

By utilizing this code, a div with position: absolute (top: 46px) on a page will become fixed to the top of the page (top: 0px) once the user scrolls to a certain point (the distance from the div to the top of the page). $(window).scroll(function (e) { ...

Tips for seamlessly integrating XHP and ReactJS for a component's implementation

Imagine this scenario: a blog with a posts feed. Upon loading the page, three <PostCard>s are already loaded from the server-side. As the user scrolls down or clicks a Load more button, new post cards should be dynamically added to the page. We have ...