Is there a way to customize the default MuiCheckbox icon in theme.ts?

How can I customize the icon default prop for Mui checkbox? I followed the instructions provided here and used a snippet from the documentation:

const BpIcon = styled('span')(({ theme }) => ({
  borderRadius: 3,
  width: 16,
  height: 16,
  ...
}));

const theme = createTheme({
  components: {
    // Name of the component
    MuiCheckbox: {
      defaultProps: {
        icon: <BpIcon />,
      },
    },
  },
});

However, I encountered the following error:

./src/theme.ts
Error: error: Expression expected
  
   |
81 |         icon: <BpIcon />,
   |                       ^

I also attempted to pass icon: BpIcon but received the following error:

Unhandled Runtime Error
RangeError: Maximum call stack size exceeded

Call Stack
Module.default
webpack-internal:///./node_modules/@babel/runtime/helpers/esm/extends.js (3:43)
deepmerge
node_modules/@mui/utils/esm/deepmerge.js (8:33)
eval
node_modules/@mui/utils/esm/deepmerge.js (19:0)

Could someone provide guidance on what mistake I might be making? Thank you!

Answer №1

To implement custom icons, you can modify your theme.ts file by changing it to theme.tsx, and then insert the code snippet below:

    const theme = createTheme({
        components: {
            // Specify the component name
            MuiCheckbox: {
                defaultProps: {
                    icon: <BpIcon />,
                },
            },
        }
    });

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

MUI TableCell components are failing to render on the page

I'm facing a frustrating issue where my table cells are not rendering properly. The header cells display fine, but the data cells do not show up in the browser. I've checked the data array of objects in Firefox's debugger and it seems to be ...

Issue TS2769: No matching overload found for this call. The type 'string | null' cannot be assigned to type 'string | string[]'

export class AuthService { constructor(private http: HttpClient, private webService: WebRequestService, private router: Router) { } login(email: string, password: string) { return this.webService.login(email, password).pipe( shareReplay(), ...

The specified type '{ rippleColor: any; }' cannot be assigned to type 'ColorValue | null | undefined'

I've been diving into learning reactnative (expo) with typescript, but I've hit a roadblock. TypeScript keeps showing me the error message Type '{ rippleColor: any; }' is not assignable to type 'ColorValue | null | undefined' ...

Closing a Bootstrap 5 Dropdown in React without using toggle feature

Currently, I am using a search field in my application that displays data as dropdown items when the user is typing. The library being utilized is React Bootstrap (bootstrap 5) and it's functioning perfectly. However, an issue arises where the dropdow ...

What steps do I need to take to create a fresh interface in useState with the help of Typescript

I'm attempting to replicate an input by utilizing useState with an interface. Each time I click on the + button, the interface should be duplicated in the state, thereby duplicating my input. Here is the code I am working on: interface newInputsInter ...

Is it possible to include array elements in a dropdown menu using React?

Imagine you have an array called const places = [" a1", "a2", "a3"]; and <FormControl variant="outlined" className={classes.formControl}> <InputLabel id="dropdown_label">Testing</InputL ...

Types are not appearing in @types/node

I have added @types/node to my project. In the index.ts file, the default node modules are being treated as type any. const fs = require('fs'); The type of fs is currently set to any. { "ts-node": { "cwd": "/User ...

The Angular2 Router encounters an issue with the URL when it contains the "&

Ever since updating to the latest version of angular v4.3.2, I've encountered an issue where all my URLs break at the & value. For instance, I have a route /:value from which I need to retrieve the value: http://localhost:4200/one&two Inst ...

incorrect implementation of react lifecycle phases

My Sharepoint Framework webpart includes a property side bar where I can choose a Sharepoint List, and it will display the list items from that list in an Office UI DetailsList Component. Although all REST calls are functioning properly during debugging, ...

What is the best way to implement Material UI's Typography in React?

Just diving into React and experimenting with Material UI for styling. I've got Grid all sorted out, but now I'm looking to incorporate Typography. My import seems solid: import Typography from '@material-ui/core/Typography' Now I&ap ...

The Material-UI button needs to be clicked three times in order for the menu to appear

Issue Overview: Currently, I am facing a problem with a menu button in my React app (Next.js) styled using Material-UI. When I click on the button to trigger the menu, it requires 3 clicks before the menu actually appears. Desired Outcome: The menu sh ...

Block-level declarations are commonly used in TypeScript and Asp.net MVC 5

In my asp.net mvc5 project, I decided to incorporate TypeScript. I created an app.ts file and installed the nuget-package jquery.TypeScript.DefinitelyTyped. Here is a snippet of the app.ts code: /// <reference path="typings/jquery/jquery.d.ts"/> cl ...

What are some strategies for maximizing the value of the initial click?

For the past few days, I've been struggling with this particular aspect of the project. Despite extensive research, I haven't been able to find a solution. The issue lies in retrieving a variable from the contextAPI. Although it updates to the co ...

Utilize JavaScript destructuring to assign values to a fresh object

When working with JavaScript/Typescript code, what is a concise way to destructure an object and then assign selected properties to a new object? const data: MyData = { x: 1, y: 2, z: 3, p: 4, q: 5 } // Destructuring const { x, z, q } = data; // New O ...

Show a loading progress indicator with a percentage until Next/React completes loading

For my upcoming SPA project, I will be fetching a 3D map and data from an API. Is there a method to incorporate a loading banner that displays the current percentage of files, components, or data loaded before the application is completely loaded? I am in ...

Having trouble accessing the name property of a select dropdown in Material UI React

Currently, I am facing an issue with implementing a select dropdown. When handling the onChange method, I am encountering a situation where event.target.name is undefined. Specifically, when I choose the 1st option, I want to be able to access 'Englis ...

Leveraging TypeScript unions within functions to handle and throw errors

As a newcomer to TypeScript, I've encountered an odd error that I need help with. I have various objects sending data to the server and receiving fresh data back of the same object type. These objects use a shared method for sending the data, so I ap ...

Unleash the power of zod by seamlessly accessing both parameters and queries

In the zod-middleware documentation, an example is provided: export async function endpointCode(req: TypedRequestBody<typeof bodySchema>, res: Response) { const typedBody = req.body; return res.json(typedBody); } This example demonstrates access ...

Step-by-step guide for launching a Next.js/Node application

Currently, I am developing a full-stack project utilizing a next.js application for the front-end and a node/express server for the API. The front-end and back-end are running on separate ports. Here is how my application is configured: https://i.stack.im ...

Exploring the integration of client-side dependency variables during data fetching in Next.js 13

I have a new Next.js 13 application up and running, where I am working on integrating client and server-side components to improve user experience and overall app performance. While it is straightforward to fetch and display data using SSR during the initi ...