Create a package themed with Material UI for export

I am attempting to create a new npm package that exports all @material-ui/core components with my own theme. I am currently using TypeScript and Rollup, but encountering difficulties. Here is the code I have:

index.ts

export { Button } from '@material-ui/core'; 

package.json

{
  "name": "@ripley-ui/core",
  "version": "1.0.0",
  "description": "",
  "main": "build/index.js",
  "module": "build/index.esm.js",
  "types": "build/index.d.ts",
  "files": [
    "build"
  ],
  ...

rollup.config.js

import external from "rollup-plugin-peer-deps-external";
...
    }
  ]
};

and tsconfing.json

{    
   ...
}

and the error it gets when importing Button into a new app is

Error: Invalid hook call. Hooks can only be called inside of a function component.
Help please!
<p><strong>UPDATE</strong></p>
<p>I made another test by creating and exporting a new component of my own. Still receiving the same invalid hook call error. Here's the code!</p>
<pre><code>import React, { useState } from "react";
...
export default TestComponent;

Is this possibly a bundler or compiler issue?

Answer №1

Upon further investigation, it became clear that the bundler error was not caused by your setup (nor webpack, parcel, or rollup). To resolve this issue, simply publish your build on npm and install it from there instead of locally. And just like that, everything should work smoothly. Cheers!

Answer №2

By removing react and react-dom from the devDependencies, I was able to successfully troubleshoot this issue.

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 universal variable cannot be accessed within the internal function of socket.on() in Socket.io

The state in react called myChat is set globally. It is being displayed in the console using console.log(NEW), but not in NEW 2. I am unable to access it in the function socket.on() where the message is received by the user. Client side const socketNewM ...

NodeJS Throws an Error: Unexpected Symbol

Looking to create a website based on Rullete. I have the necessary code and scripts, but when I try to run the script, I encounter an error. [SyntaxError: Unexpected token <] SyntaxError: Unexpected token < at Object.parse (native) at Reques ...

What is the best way to execute Laravel mix using a custom URL?

I am currently working on an application that needs to be deployed on a staging server due to its dependencies on other servers within the network. Building it locally is not feasible in this case. The application is developed using Vue.js and Laravel. Du ...

Error Deploying Firebase Functions

I've been dedicated to this project for quite a while. I have deployed it numerous times without any issues. However, after revisiting the project following a month-long break, I encountered an error upon running firebase deploy --only functions: i ...

Send a callback function from the main component to a nested component in React

TASK: Implement a callback function in the parent component to toggle the sidebar in the child component. The following code snippet shows how to open the sidebar: <Sidebar show={status} /> <button onClick={() => setStatus((status) => !s ...

Retrieve data from each URL listed in a JSON array using React

My json file structure was as follows: [ { "name": "google", "route": "/google", "url": "www.google.com" }, { "name": "bing", "route": " ...

What is the best way to include a variable or literal as a value in styled components?

When it comes to managing various use cases, I always rely on props. However, I am currently facing a challenge in changing the border color of a styled input during its focus state. Is there a way to utilize props for this specific scenario? Despite my f ...

Material-UI: Avoid onClick event firing when clicking on an element that is overlapped by another in a sticky Table

I have a unique setup in my table where each row, including the header row, begins with a checkbox. This header row has a sticky property. As I scroll through the table, rows start to move behind the header row. If I try to click the checkbox in the heade ...

Linking an external URL with a button using Material UI - A simple guide

I'm currently exploring Material-UI and testing my web application on localhost. I've added a button that should redirect users to an external URL (currently set as www.google.ca) when clicked. However, instead of redirecting to the correct URL ( ...

Angular: issue with form validation - password matching is not functioning as expected

I have successfully implemented the registration form with basic validations The code I used can be found in: registration.html <form #registrationForm="ngForm" (ngSubmit)="onFormSubmit()"> ... <div class="form- ...

Exploring the World of React Variables

Recently, I've been diving into the world of React and encountered some challenges while styling my components. Personally, I find it more organized to style within the same JavaScript file instead of having a separate one. However, I'm curious a ...

How to retrieve TypeScript object within a Bootstrap modal in Angular

Unable to make my modal access a JavaScript object in the controller to dynamically populate fields. Progress Made: Created a component displaying a list of "person" objects. Implemented a functionality to open a modal upon clicking a row in the list. ...

The type does not meet the requirements set by the class it is inheriting from

Currently, I am in the process of working on a WebSocket Secure (WSS) server utilizing the Node ws library which can be found here. More specifically, I am following the approach outlined in this particular question, although its relevance is yet to be det ...

Encountering a server issue: Server Error Element type is invalid

I encountered an error message on my localhost: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's define ...

Tips for hiding the frame of a React MUI Select component

I am having trouble figuring out how to remove the border around the <Select> component from the React Material UI library. In the image below, you can see that when the <Select> component is not selected, it has a black border/frame. https:// ...

What are the different ways to customize the indicator color of React Material UI Tabs using hex

Just got my hands on this amazing Material UI component <Tabs textColor="primary" indicatorColor="primary" > <Tab label="All Issues"/> </Tabs> The documentation states that indicatorColor and textColor can only be set to ' ...

Guide to making a Grid element interactive using the Link component

PostsList component is responsible for rendering a list of posts. The goal is to enable users to click on a post item and be redirected to the specific post's link. const PostsListView = ({ posts, setError, isloggedin }) => { const [redirectCre ...

Displaying every nth image in a new row of a CSS grid

I have a react component and I want to arrange 3 photos inline in a row with their names below each photo, and then continue in new rows for the next set of 3 elements and so on... I attempted to use :nth-child(3n+1) but encountered some issues... const P ...

Is there a way to position two Grid elements to the left and one to the right in Material UI, especially if the first Grid element has a specified width

I'm currently using Material UI and have a Grid layout with three items. The left item needs to have a fixed width of 240px and be aligned to the left. The middle item should be left justified and can have any width, containing buttons that I've ...

What is the best way to extract and count specific values from a JSON file using JavaScript?

My JSON data looks like this: /api/v1/volumes: [ { "id": "vol1", "status": "UP", "sto": "sto1", "statusTime": 1558525963000, "resources": { "disk": 20000000 }, "used_resources": { "disk": 15000000 }, "las ...