The animation for the login and registration modal is malfunctioning and not functioning as

I am currently working on implementing a login/register modal in React, inspired by a TypeScript example I came across.

This is how the login section looks:

https://i.sstatic.net/ECvv9.png

The goal is to:

  • When the "Sign up" button is clicked, it should trigger a transition where the orange section transforms into a signup form, and the left side turns into an orange layout for signing in.

Currently, I have managed to create the login layout, but clicking on the signup button is not producing any action.

At this point, the code is giving an error about this.container.current not having a .current.

Below is the provided code:

import React from "react";
import { Modal } from "react-bootstrap";
...

Additionally, here is the corresponding CSS:

h1 {
    font-weight: bold;
    margin: 0;
}
...

It seems like there is a small link missing to connect everything together and make it functional.

For reference, I started with the following codepen link: https://codepen.io/FlorinPop17/pen/vPKWjd

Answer №1

It's best to avoid directly manipulating the DOM, as React is designed to handle those tasks for you. You likely won't need to interact with the DOM manually very often.

When working with class components, the proper way to create a reference to an element is through React's createRef() method. It's worth considering if you truly need a ref in your specific scenario:

const myRef = React.createRef();
...
<button ref={myRef} style={whiteBtnStyle} class="ghost" id="signUp">Sign Up</button>

When attaching event handlers in JSX, the preferred approach in React is to use inline event handlers:

<button onClick={onSignUpClick} style={whiteBtnStyle} class="ghost" id="signUp">Sign Up</button>

Instead of defining inline functions directly in your JSX, consider declaring instance methods within your component to prevent unnecessary function recreation on each render:

onSignUpClick = () => {
   this.setState({
     rightPanelActive: true
   });
}

Don't forget to utilize className instead of class when binding CSS classes in JSX to avoid conflicts with JavaScript's reserved keywords:

<div className={`container ${this.state.rightPanelActive ? "right-panel-active" : ""`} id="container">

Lastly, be cautious when using ids for elements to ensure they are unique throughout your page. Duplicate ids, such as in separate modal components, can lead to invalid HTML:

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

Merge Razor with Ajax and JSON

I have been struggling to get the following components to work together without success. The goal is to populate the mediaId's combobox with respective values based on the selection in the target combobox. Currently, I am only simulating the values fo ...

Node.js impressively stores files without file extensions

app.post('/file_upload', function (req, res) { var form = new formidable.IncomingForm(); form.uploadDir = path.join(__dirname, '/uploads'); files = [], fields = []; form.on('field', function(field, ...

What is the process for sending a JSON response and then redirecting to an HTML page after a successful event in Node.js using Express?

Trying to send a JSON response and redirect the page simultaneously in Express.js. Need help figuring out how to achieve this. Is it possible to redirect in Express.js while sending a JSON response to the client? The goal is to use this JSON data to render ...

Hold off on addressing the nested loops within a TypeScript subscription

Goal: Ensure all nested loops complete processing before returning final value. Problem: Final value returned prematurely, before completion of loop processing. In the code snippet below, I am sending paramListToComplete to a data service for creating a ...

Encountering a problem with the getJSON() function within the app.js file connected to a solidity

Currently, I am working on developing a simple dapp in Truffle. However, I encountered an error when using $.getJSON() function in my app.js file. Below is a snippet of my app.js: App ={ web3Provider: null, contracts: {}, init: function (){ return A ...

Setting up Apache VirtualHost to work with Create-React-App

Currently, I am in the process of developing a project for a particular company. The API provided by this company has some restrictions in place - it only allows requests from their own host and 'xyz.localhost'. In the initial stages, I built th ...

Creating a resilient node websocket client with enhanced security (overcoming the challenge of verifying the initial certificate)

What's Working? I successfully created a node server using WebSocket technology. I used the library WebSocket-Node and added key/cert to my HTTPS/secure websocket server as shown below: import WebSockerServer from "websocket"; import fs fro ...

What is the process of embedding a string with pug code into a pug file?

How can I interpolate a string with pug formatted code in a pug file? Here is what I have tried: - var text = "i.home.icon" div= text div !{text} div #{text} div ${${text}} div {{text}} div {text} div \#{text} div \{text} div ${text} div # ...

"Exploring the power of JQuery in adding new elements and accessing the newly appended

I have a code that appends some HTML to a div using JQuery like this: $("#divId").append("<div class='click' data-id='id'></div>"); and I want to access the appended div by clicking on it like so: $(".click").click(functi ...

Transform the text with a stylish touch within a 'textarea' element

I am currently working on a form with the following design: At the moment, I am at this particular stage and focusing on some minor details: One issue I have encountered is that the "Your text..." appears stuck to the top left corner of the textarea. I a ...

React- Struggling to modify state from child component using function declared within a parent component

This is my main component: import React, {useState} from 'react'; import SearchBar from '../components/SearchBar'; import WeatherDisplay from '../components/WeatherDisplay'; import LocationInfo from '../components/Locat ...

What could be causing the Express error when this.props.param.match.id is coming up as undefined?

I am currently delving into the world of Express.js, attempting to understand how to utilize it effectively. However, I am encountering an issue where I am unable to retrieve an id value from this.props.match.params. Here is how my express route is set up ...

Steps to turn off fancybox for mobile and show the full image instead

In this scenario... I am seeking a way to deactivate fancybox functionality on mobile devices. I have already discovered one method to disable it... And now I want to directly show the large image in the a href="xxx_large.jpg" instead of using the img src= ...

Angular directive ng-if on a certain path

Is it possible to display a specific div based on the route being viewed? I have a universal header and footer, but I want to hide something in the header when on the / route. <body> <header> <section ng-if=""></section&g ...

When using `element.addEventListener`, event.target will be the target

When working on a solution, I initially bound event listeners to multiple targets within the same container. I am curious to know if anyone has noticed considerable performance improvements by using just one event listener and leveraging the target of the ...

Looking for a Horizontal Layout?

@foreach (var item in APModel) { <div class="row row-cols-1 row-cols-md-2 g-4"> <div class="col"> <div class="card" style="width: 18rem;"> <img src="h ...

Is it possible to use one table as a background and place another table on top of it?

Currently, I am designing an email template and due to restrictions, I can only use tables. I am looking for a solution to meet my requirements using tables. Since all the content is dynamically generated via an RSS feed, images cannot be used in this ca ...

Several mistakes occurred involving auth0, react, apollo, babel, and webpack

I seem to be facing some challenges while trying to integrate auth0 into my project. Every time I fix one issue, another one pops up and it's always the same trio of errors: -require is not a function -window is not defined -missing class properties ...

Tips on how to prevent certain classes from being impacted by a hue-rotate filter applied to all elements on a webpage

I am currently in the process of adding a feature that allows users to choose between a dark or light theme, as well as select a specific theme color for the app. The implementation involves using CSS filters such as invert(1) for the dark theme and hue-ro ...

The FormData object appears to be blank, even though it was supposed to be populated when attempting to send a PDF file using a multipart FormData POST request in Cypress

I am attempting to send a PDF file as a POST request. The API supports the use of @RequestPart and @RequestParam: @RequestPart("file") MultipartFile file; @RequestParam(value = "document-types", required = false) Set<String> documentTypes; My appro ...