App.jsx line 11 is throwing an error due to an undefined property 'TodoComponent'

While attempting to style a ReactJS component, I encountered an error in my browser's development console:

App.jsx:11 Uncaught TypeError: Cannot read property 'TodoComponent' of undefined at App.render (App.jsx:11)

I have tried importing using the following syntaxes:

In App.jsx:

import {styles} from ...
import {styles as styles} from...

In styles.js :

export default styles... 
export styles...

All have failed.

Here is my directory tree structure:

src content directory - ls :
App.jsx  styles.js

Here is my App.jsx code snippet:

import React from "react";
import { render } from "react-dom";
// Import the styles
import {styles} from "./styles.js";


class App extends React.Component {

  render() {
    return (
    <div style={styles.TodoComponent}>
(...)

And here is my style.js code snippet:

var TodoComponent = {
      width: "300px",
      margin: "30px auto",
      backgroundColor: "#44014C",
      minHeight: "200px",
      boxSizing: "border-box"
    };

    var styles = {


    TodoComponent: TodoComponent,
( other styles...) 
    };

This is my webpack.config.js configuration:

var webpack = require("webpack") ;
var path = require("path") ;
var ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports= {
mode: "development",
devtool : "source-map",
context : __dirname + "/src",
entry : { app : __dirname + "/src/App.jsx" },
output : { path: path.resolve(__dirname, "public/"),
          filename : "frontend.bundle.js"
},
module: {
   rules: [ {
     test: /\.js|jsx$/,
     exclude: /node_modules/,
   include: path.resolve(__dirname, "src"),
     use: [
       {
   loader: 'babel-loader',
   options: {
     presets: ["es2015", "stage-1", "react"]
   }
       }
     ]
   },
 {
 test: /\.css$/,
 use: [
   { loader: 'style-loader' },
   {
     loader: 'css-loader',
     options: {
       modules: true
     }
 }
 ]}
]},


optimization : {

 splitChunks: {
     chunks: "async",
     minSize: 3000,
     minChunks: 1,
     maxAsyncRequests: 5,
     maxInitialRequests: 3,
     automaticNameDelimiter: "~",
     name: true,
     cacheGroups: {
   vendors: {
       test: /[\\/]node_modules[\\/]/,
       priority: -10
   },
     default: {
       minChunks: 2,
       priority: -20,
       reuseExistingChunk: true
   }
     }
 }
},
devServer: {
  proxy: {
  "/api": "http://localhost:7000"
},
 contentBase: path.resolve(__dirname, "public/"),
 open : true
}
};

Configuration in config.babelrc:

{
  "presets": ["env", "react", "stage-0"]
}

Answer №1

To make it available elsewhere, you must export the following:

var TodoStyle = { width: "300px", margin: "30px auto", backgroundColor: "#44014C", minHeight: "200px", boxSizing: "border-box" };

export const customStyles = { TodoStyle: TodoStyle, };

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 References in React Components

One of the challenges I am facing involves a Container that needs references to some of its child components: const Container = () => { const blocks: HTMLDivElement[] = []; return ( <div> <Navigation currentBlock={currentBlock} ...

Leveraging Underscore in ReactJS applications

I'm encountering an issue with integrating Underscore into my ReactJS project. When I attempt to run my ReactJS class, the following error arises: Uncaught ReferenceError: _ is not defined index.html <html> <head> <meta http-equi ...

I have a website hosted on Heroku and I am looking to add a blog feature to it. I initially experimented with Butter CMS, but I found it to be too pricey for my budget. Any suggestions on

I currently have a website running on Heroku with React on the front end and Node.Js on the back end. I want to incorporate a blog into the site, but after exploring ButterCMS, I found the pricing starting at $49 to be too steep for my budget. My goal is ...

Deleting an element from an array stored in local storage with the help of jQuery

Summary: Developing a front-end wish list feature Tech Stack: Utilizing HTML5 (localStorage), CSS, and jQuery Key Features: Ability to add and delete items dynamically with real-time count display Challenge: Issue encountered when trying to remove added ...

Developing a custom function that analyzes two distinct arrays and sends any corresponding pairs to a component

I'm in the process of developing a component that utilizes two arrays. These arrays are then mapped, and the matching pairs are sent down as props to a child component. The goal is to create a list component that retrieves the arrays from the backend ...

Tips for establishing communication between a React Native webView and a React web application

I am currently working on establishing communication between a webView in react-native and a web-app created with React-360 (and React). I am utilizing the react-native-webview library and following a guide for creating this communication. You can find the ...

Incorporating an Icon into the StackNavigator Bar to access the drawerNavigator in a react-native application

I've been attempting to include a menu type icon in the header of my stack navigator using the code below: import React, { Component } from 'react'; import { createStackNavigator, HeaderTitle } from '@react-navigation/stack'; impor ...

Struggling to locate the Twitter direct message input box with Xpath in Selenium

I have been struggling to locate the textbox element using the find_element_by_xpath() method. Unfortunately, every time I try it, I receive an error stating that the element cannot be found. Here is the specific line of code in question: Despite attempti ...

Providing API parameters to ReactJS components imported in jsx

I have a reg_form.jsx file that includes a GenderField with three options defined by the backend and sent through an API. These values are crucial for validation on both the backend and frontend, so I want to avoid duplicating them. With around 30 fields ...

Problem with chip input: selected value not appearing on display

I have a drop-down menu with options displayed as chips. I am able to retrieve the value selected using console log, but it does not appear in the select box. What could be causing this issue? handleChange = event => { this.setState({ badge : ev ...

Is it possible to adjust the color and placement of the CircularProgress component?

Utilizing the CircularProgress component provided by Material has been a goal of mine. In my efforts to achieve this, I developed a component with the intention of customizing its color: import React, { Component } from 'react'; import { withSt ...

Kudos to the information provided in the table!

My JSON data is structured like this: { description : "Meeting Description" name : "Meeting name" owner : { name: "Creator Name", email: "Creator Name" } } I want to present the details in a table format as follows: Meeti ...

Steps to display a JSX component stored in a variable

Presently, I am implementing an if/else statement within my code to determine the content that will be displayed in the JSX element named 'signupMessage'. Subsequently, I render the contents of this 'signupMessage' element. render() { ...

The computer is having trouble processing the "replace" property because it is undefined

Currently facing an issue while attempting to fetch the current path. The error message displayed is Cannot read property 'replace' of undefined. Can anyone provide assistance in resolving this problem? handleClick= (event: SyntheticMouseEvent&l ...

Creating multiple versions of a website based on the user's location can be achieved by implementing geotargeting techniques

It may be a bit challenging to convey this idea clearly. I am interested in creating distinct home pages based on the source from which visitors arrive. For instance, if they come from FaceBook, I envision a tailored home page for FaceBook users. If they ...

Tips for Locating an Element by Its Attribute in JQuery

I currently have a variable that holds a list of selects, and my goal is to filter out only those with a 'dependsOn' attribute set to 'EventType'. My initial attempt below doesn't seem to work as intended and returns a count of 0: ...

Image not showing up on HTML page following navigation integration

Having trouble with my responsive website setup - the background image for ".hero-image" isn't showing up after adding the navigation. Google Chrome console is throwing a "Failed to load resource: the server responded with a status of 404 (Not Found)" ...

What to do when IE6/IE7 margins disappear after moving a relatively positioned floated div using jQuery's .hover()?

Sharing my code with you: http://jsbin.com/uhera3/edit Encountered an issue where the relatively positioned floated divs move to the left in IE7 when using jQuery's .hover() function. Any insights on how to resolve this problem? ...

Creating customized JQuery UI tabs to perfectly accommodate the available horizontal space

Can JQuery UI Tabs be modified to fill the horizontal space and stack to the left? In order to achieve this, could we consider using a markup like the one below: <table width="100%"> <tr> <td> ...content... </td> ...

Mastering the Art of Unit Testing React Components

In my current project, I am using the testing tools Jest and Enzyme to test a React component. This component relies on a third-party React UI library called Ant Design (Antd). To better illustrate my question, I have provided a simplified version of the c ...