Incorporating a picture backdrop into a button element in a React Typescript component

I am working on a React project with TypeScript and using a Material UI library. I am trying to set a background image for a button, but when I use src or imageURL, it gives me a TypeScript error. The CSS style also does not show the picture. Here is my code:

const notificationIcon = require ('./../../images/notification-icon.png') 
const avatarImage = require ('./../../images/avatar.png') 

const CustomButton = ({
  handleToggle, handleClose, handleOpen, setOpenState, isOpen
}: DropdownButtonProps) => (
  <Button onClick={handleToggle} style={{backgroundImage: `url(${notificationIcon})`}} square>
  </Button>
)
function Navbar () {
  return (
    <>
      <TopBar style={{ backgroundColor: '#e6edec' }}>
        <TopBarSection>
          <TopBarTitle>
            <Avatar imgUrl={avatarImage} name='John Doe' style={{ fontFamily: 'Arial', fontSize: '20px' }} />
          </TopBarTitle>
          <Dropdown ButtonComponent={CustomButton}>
          <DropdownItem>Click me</DropdownItem>
        </Dropdown>
        </TopBarSection>
      </TopBar>
      <section
        style={{
          padding: 50,
          textAlign: 'center'
        }}
      >
      Some content
      </section>
    </>
  )
}

export default Navbar

Answer №1

Instead of that, try the following:

<Button onClick={handleToggle} style={{backgroundImage: `url(${noticon})`}} square>

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

Implementing ReactJS production build with HTTPS on Express server

After successfully deploying my React app to a production server using Express, I've encountered an issue when it comes to securing it with SSL certificates. Below is the code snippet that worked for deployment: const express = require('express& ...

Having trouble with clearing divs function not working as expected

I'm facing a challenge in properly aligning 3 div elements without resorting to adding padding at the bottom of the wrapping div, which isn't the most practical solution. Check out the issue demo here How would you suggest addressing this parti ...

Tips for utilizing a personalized extension in Visual Studio Code

Embarking on my HTML journey, so please bear with me. I've been watching tutorial videos to get a better grasp of it, and one of the tutorials I'm following shows how to create a resume on GitHub using VS Code. Check out the video here At 3:44 ...

How to show a tooltip inline by utilizing CSS styling

Working on a sticky side bar menu with a tooltip feature. While it appears correctly in Chrome and Safari, the tooltip is off-center in IE. This snippet seems to be causing the issue: /* Vertically center tooltip content for left/right tooltips */ .tool ...

The MUI Drawer does not open with styled components when the variant is set to temporary

I have customized a MuiDrawer component to apply some unique styling. Despite setting the variant to temporary, the Drawer fails to open when the open prop is passed. Strangely, switching the variant to permanent results in the Drawer being displayed succe ...

Complete a checkbox entry form and showcase it within a "division" on the current page

Hello everyone, I need some help. I have a form that I want to send to a specific div on the same page. This is what I am aiming for. I have a floating div named "basket" in the top right corner of my page where I want the form data to be displayed after s ...

Using TypeScript to apply a typed decorator function to a subclass

I've taken on the challenge of creating a node.js and MongoDB ORM library similar to "Entity Framework" using TypeScript. This library will allow users to define a Model class (e.g. Person) that extends a Base class. The class decorator will enhance ...

Align and resize image using CSS styling

Seeking assistance on centering and cropping images using CSS. Tried implementing the technique from this specific article. However, experiencing inconsistencies in device UI output. Can someone shed light on this behavior? Scenario: The objective is t ...

Guide on executing get, modify, append, and erase tasks on a multi-parameter JSON array akin to an API within Angular

I have a JSON array called courseList with multiple parameters: public courseList:any=[ { id:1, cName: "Angular", bDesc: "This is the basic course for Angular.", amt: "$50", dur: & ...

Continue extending the footer as the screen size decreases

Could anyone offer some assistance? I'm currently working on a project and facing issues with getting the footer to always be pushed down as the screen size decreases. As of now, my content is going under the footer instead. Any help would be greatly ...

Python's selenium did not locate the specified CSS element

After transferring the code from Selenium IDE to Python, the selenium test was functioning properly except for clicking on the item and scrolling clicks smoothly on an item. Here is the HTML selenium code: <?xml version="1.0" encoding="UTF-8"?> ...

Add the specified HTML tag to the existing document. An error has occurred: HierarchyRequestError - The action would result in an invalid node

During my testing of a React/TypeScript project using Jest + Enzyme, I encountered an issue when trying to append an HTML tag. The error occurred with the following unit test code: const htmlTag: HTMLElement = document.createElement('html'); htm ...

The declaration module for Node-json2html was not located

Has anyone encountered issues with node-json2html? I installed it through npm. However, an error keeps popping up: The declaration file for module node-json2html could not be found. Just to add, I am working with ReactJS. ...

Hovering over elements with the FireFox CSS transition 'transition-all' can sometimes lead to flickering and unexpected behavior

Can someone help me understand why I am experiencing a flickering effect on an element when using transition: all 0.5s ease-out; in FireFox? It's difficult to describe, but you can see it happening in this live example here: (take a look at the logo ...

Can I incorporate a new React project into an existing React project or webpage?

I have a question about deploying my React project. After using npm run build, I now have a build folder with all the necessary files. My project is more complex than the simple "like button" example on React.org. It includes multiple sub-components, fetc ...

Change the dimensions of a picture from 4:3 to 16:9 while maintaining its responsiveness using CSS

Imagine I have this image with a 4:3 aspect ratio and dimensions of 640x480: https://i.sstatic.net/p4xRM.jpg Here is the code used to display it: <img src="../static/images/image4-3.jpg" class="img-fluid" alt=""> Now ...

Adjusting the header background color as the user scrolls on a Next.js webpage

When looking at the code below: import { useEffect } from "react"; import Link from "next/link"; import styles from "./header.module.css"; import { useRouter } from "next/router"; export default function Header() { ...

Unable to locate the "shop" within the "Connect" environment

I'm facing an issue with my app that utilizes a js-common library I created. The library exports multiple components, but when I try to import one of them into my app, I encounter the following error: "Could not find "store" in the context of "Connec ...

Encountering a FirebaseError while executing a Firebase query with a "

I'm currently using "firebase": "^9.9.0", which means I am working with web version 9 syntax. My goal is to retrieve a document based on its field value, but I've been encountering difficulties. Despite being able to fetch all ...

Fading away backdrop images for the header

I've created a header class in my CSS with the following styling- header { background-image: url('../img/header-bg.jpg'); background-repeat: none; background-attachment: scroll; background-position: center center; .backg ...