The onClick event for the OnButtonSubmit function seems to be malfunctioning in ReactJS

When attempting to utilize the onClick event for a button in React, my goal is to simply have it log "clicked" in the console. However, this functionality is not working as expected.

The Component where the onClick event is being called looks like this:

import React from 'react'
import 'tachyons'

const ImageLinkForm=({OnInputChange,OnButtomSubmit}) =>{
    return (
        <div>
            <div className="center mt5 form br3 shadow-5 w-50">
                <input className="f3 pa2 w-70 center" type="Text" onChange={OnInputChange}></input>
                <button className="w-30 f4 grow link ph3 pv2 dib white bg-black pointer ma1" onClick={OnButtomSubmit}>Detect</button>
            </div>
        </div>
    )
}

export default ImageLinkForm

The component is utilized in App.js like so :

<ImageLinkForm OnInputChange={this.OnInputChange} OnButtonSubmit={this.OnButtonSubmit} ></ImageLinkForm>

The definitions of the functions are:

OnInputChange=(event)=>{
    console.log(event.target.value);
  }
OnButtonSubmit=()=>{
    console.log('clicked');
  }

I'm unable to identify the issue here. PS: the onInputChange function is functioning correctly

Answer №1

It appears to be a simple typographical error:

OnButtomSubmit // correction: change m to n

Answer №2

handleButtonClick=()=>{
    console.log('clicked');
  }

There seems to be a typo when passing it in from the props

const ImageLinkForm=({OnInputChange,OnButtomSubmit}) =>{ // You wrote OnButtom with an incorrect m instead of n

Answer №3

There seems to be a small typo in the code:

<ImageLinkForm OnInputChange={this.OnInputChange} OnButtonSubmit={this.OnButtonSubmit} ></ImageLinkForm>

You are passing OnButtomSubmit as a prop in the component file, but then using OnButtonSubmit when actually utilizing that prop.

I hope this explanation clears things up for you!

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

Utilizing BootStrap 4 to ensure uniform image sizes within a row of columns

I'm facing a challenge in creating a row of 4 images that are responsive and uniform in size, despite being different dimensions (640x799, 640x479, ...). I've attempted to use columns and img-fluid to achieve this, but the shorter images do not f ...

What is the best way to implement a bootstrap progress bar without using any JavaScript libraries, or if necessary, using a

Can we simplify the creation of a progress bar using JavaScript only? progressBarElem = document.createElement("div"); progressBarElem.className = "progress-bar" progressBarElem.setAttribute("role","progressbar") progressBarElem.setAttribute("aria-valueno ...

Creating interfaces within props is essential for defining the structure of components

I'm trying to pass an Interface to one of my components, but I'm running into some issues with my approach. Here's what I have so far: import { InterfaceType } from "typescript"; type Props = { dataType: InterfaceType } export default ...

Why won't the props pass down to the child component?

I am facing an issue while trying to pass two values as props from a React component "App" to its child "Todo". The values being passed are "title" and "completed" from a json placeholder API. The JSON object is correct and has been verified. The problem ...

Leverage the power of Fluentlenium to effortlessly upload a file using dropzone.js

Currently, I am trying to create a test for file uploading using Fluentlenium and DropZone.js (). Dropzone.js operates within a modal where users can drag and drop files or upload them traditionally. However, the test crashes as soon as the upload button ...

Show every element of an array except for the selected index using Javascript

I'm curious, is there a way to display array indexes in reverse order? Let's consider the following array: var color = ["red", "green", "blue", "yellow"]; console.log(color[2]); Normally, the console would display "blue", right? But what if we ...

What could be causing the error message "userID is not defined" to appear?

Can someone assist me with this script issue? I keep receiving the error message "userID is not defined." I'm attempting to bulk modify licenses following a tutorial on https://www.youtube.com/watch?v=e4KTAytOeyA function updateLicenses() { var u ...

Encountering a React error: "TypeError: Unable to access the 'imageUrl' property of undefined"

In my programming project, I have a list of items in an array that are passed through state from the App component to the QuizApp component and then to the Turn component. It seems like the issue lies in the Turn component not being able to read the props ...

Adding Quasar to Your Nuxt App: A Step-by-Step Guide

I'm looking to incorporate Quasar into my current Nuxt project. As I delved into the Quasar documentation, I noticed that the installation guide only highlights their own CLI tool, which doesn't offer support for Nuxt integration. Additionally, I ...

Get the value of a JSON in template strings

After querying objects from a table, they are stored in objarr. How can I retrieve these values in the UI using JavaScript? from django.core.serializers import serialize json = serialize("json", objarr) logging.debug(type(json)) response_dict.update({ ...

Node.js is causing issues with the functionality of Bootstrap carousel controls

I'm currently working on a sailing website, and I've run into an issue with the left and right controls and indicators in the testimonials section. They don't seem to be responding properly. Could this be due to me not including or calling t ...

Align the content vertically in a Bootstrap column that takes up the full height

Is there a way to make sure that the columns in a row are the full height of the row while keeping the text content vertically centered? <div class="row fixed-bottom mobile-navbar align-items-center"> <router-link to="/" cl ...

Step-by-step guide on integrating a specific location into Google Maps using React.js

I'm in the process of revamping my website using Reactjs. I want to incorporate a specific Google location with reviews on the map, similar to how it appears on this example (My current website is built on Wordpress). As of now, all I've been ab ...

Django: Struggling with static files and navigating paths for CSS rendering

Sorry to ask, but I'm struggling with a problem and could use some help: My project directory has the following structure (there are more directories, but for now let's focus on these): projectfolder/ wsgi/ openshift/ templates ...

Why does my text keep drifting towards the left edge?

After spending a day learning CSS and HTML, I decided to recreate a website from a YouTube video and add my own customizations. I was able to center the text in my introduction successfully. However, upon reviewing my progress (see screenshot here), it is ...

What is the method for modifying the background color of the inner circle in a highchart doughnut chart?

Trying to Modify the Background Color of a Highchart Doughnut Desired Outcome https://i.sstatic.net/Fk9oS.png Current Outcome https://i.sstatic.net/CTZqZ.png JS Fiddle Link : https://jsfiddle.net/shantanugade/f5ojh13z/1/ Seeking assistance with this is ...

Difficulty maintaining hover state on menu while navigating to submenu on an HTML page

I successfully implemented a side menu that displays the submenu when hovering over menu items. However, I am encountering two issues: 1. When I hover over a menu item and the submenu appears, the hover state of the menu item disappears. I would like the m ...

Exploring Symfony2: Enhancing user experience with dynamic form submission and dropdown menu updates

Starting from the beginning. I have a tab-panned layout with links. Upon clicking a link, a drop-down checkbox form is injected directly into the HTML through $(".dropdown-toggle").click(function() { var projectId = $("#permission-form").attr("data-p ...

Is there a way to stabilize the Spotlight position when scrolling in React-joyride library? My current setup is causing it to shift and I

Encountering a spotlight issue while scrolling. Struggling to address the aforementioned positioning issue while utilizing React-joyride to create a website tour. Seeking guidance on resolving the mentioned problem. Any assistance would be appreciated! ...

What is the method to locate an iframe in Java Selenium without a specified name or id?

Is there a way to select an iframe using Selenium in Java if the element doesn't have a Name or Id attribute? I need to use the switchTo method to switch to it. The website where I am looking for the iframe is jklm.fun and the xpath of the iframe is ...