The method of utilizing React with Redux to display component properties

  • I am currently trying to include my common component in my main.js file
  • Successfully implemented this
  • However, when attempting to print my Redux data values in the common component,
  • I created a method called handleClickForRedux to handle this task.
  • Even after including mapStateToProps and mapDispatchToProps,
  • The value is still not printing at the specific line.
    console.log("event redux props--->", props);
    
  • Could someone advise me on how to resolve this issue?
  • I have provided my code snippet and sandbox link below for reference.

https://codesandbox.io/s/react-redux-example-265sd

scroll.js

import React, { useEffect, useState, Fragment } from "react";
import PropTypes from "prop-types";
import { withStyles } from "@material-ui/core/styles";
import Card from "@material-ui/core/Card";
//import CardActions from "@material-ui/core/CardActions";
import CardContent from "@material-ui/core/CardContent";
import Typography from "@material-ui/core/Typography";
import Drawer from "@material-ui/core/Drawer";
import { bindActionCreators } from "redux";
import * as actionCreators from "../actions/actionCreators";

import { connect } from "react-redux";
import { compose } from "redux";

function SportsMouse(classes, props) {
  // const [canEdit, setCanEdit] = useState(false);

  function handleClickForRedux(event) {
    console.log("event--->", event);
    console.log("event redux props--->", props);
  }

  return (
    <Card>
      <div onClick={handleClickForRedux}>I am here </div>
    </Card>
  );
}

SportsMouse.propTypes = {
  classes: PropTypes.object.isRequired
};

function mapStateToProps(state) {
  return {
    posts: state.posts,
    comments: state.comments
  };
}

function mapDispatchToProps(dispatch) {
  return bindActionCreators(actionCreators, dispatch);
}

export default compose(
  connect(
    mapStateToProps,
    mapDispatchToProps
  )
)(SportsMouse);

main.js

import React from "react";
import { Link } from "react-router-dom";

import Scroll from "../commonComponents/scroll";

const Main = props => {
  const { children, match, ...rest } = props;
  return (
    <div>
      <h1>
        <Scroll />
        <Link to="/">Reduxstagram</Link>
      </h1>
      {React.Children.map(children, child => React.cloneElement(child, rest))}
    </div>
  );
};

export default Main;

Answer №1

Although material-ui components only accept a single argument, the `classes` variable resides within the `props`. By logging `console.log(classes)`, you can observe that it encompasses all of your props, including material-ui's styles. The correct syntax should be as follows:

function SportsMouse(props) {

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

Creating column gaps that remain consistent when resizing a webpage is essential for maintaining a clean and organized layout

Visit my current site [This is the HTML code for my website:][2] <div class="column-box" style="width: 100%"></div> <div id="column1" style="float:left; margin:15; width:33%;"> <p>Sara Adams<br> I am a Web Developer and C ...

Axios - Error: Promise Rejected - The request was unsuccessful with a 500 status code

The Axios post request in my code for adding new articles is not going through, and I am encountering an error: Failed to load resource: the server responded with a status of 500 (Internal Server Error) createError.js:17 Uncaught (in promise) Error: Requ ...

Issue: encountered an ECONNRESET error when attempting to read using the request module in mode.js

When attempting to download and parse large XML files from affiliate sites without a proper API, I encounter the same error consistently while using the request module for Node.js. Error: read ECONNRESET at exports._errnoException (util.js:746:11) at TCP. ...

Leveraging the Nest JS Validation Pipe in combination with the class-transformer to retrieve kebab-case query parameters

Can someone help me with using the Nest JS Validation Pipe to automatically transform and validate my GET Request Query Params? For example: {{url}}/path?param-one=value&param-two=value In my app.module.ts, I have included the following code to impl ...

Sorting arrays in javascript

My JavaScript array is structured like this: var data_tab = [[1,id_1001],[4,id_1004],[3,id_1003],[2,id_1002],[5,id_1005]] I am looking to organize and sort them based on the first value in each pair: 1,id_1001 2,id_1002 3,id_1003 4,id_1004 5,id_1005 ...

Vue transition unexpectedly ending in the wrong position due to nested transitions

I've encountered an issue while trying to implement a transition on a child div within a 'parent' div that already has its own transition. It seems like the child transition is conflicting with the parent transition, causing it to end up in ...

Paginating content without the need for a database

Seeking assistance on implementing pagination for displaying trading history API responses, without utilizing a database. Can anyone provide guidance and help with the necessary logic? Here is an excerpt of my code: <?php error_reporting(E_ALL) ...

Using Selenium WebDriver to Extract Variables from JavaScript SourceCode

Currently, I am dealing with a web page source code that utilizes JavaScript to display text. Below is an excerpt from the source: var display_session = get_cookie("LastMRH_Session"); if(null != display_session) { document.getElementById("sessionDIV") ...

Having trouble accessing a JavaScript variable in Javascript due to reading null property 'value'

What I Require I am in need of passing a URL variable from an HTML document to a JavaScript file. HTML Snippet <script> var urlParam = "{{ page_param.asy_request | replace('&','&')}}"; urlParam = urlParam.rep ...

Socket connection in Vue not activating

I've been experimenting with incorporating Vue.js and sockets together, but I'm encountering an issue where my Vue application isn't receiving socket events. Despite following online tutorials, the example provided doesn't seem to work ...

What is the best way to position a container div over another container using Bootstrap or CSS?

https://i.sstatic.net/q1qGi.png I'm working on a Bootstrap 4 layout where container B needs to overlay part of container A. I want to achieve a design where container B appears on top of container A. Any suggestions or references on how to achieve th ...

Unveiling the Technique: Adjusting Field Visibility When Dropdown is Altered

I tried to find a solution on Stackoverflow for displaying/hiding a field based on dropdown selection using either jQuery or inline JavaScript. However, I am facing difficulties when implementing this within a table. Let's start with an easy approach ...

Use the .map method to transform JSON data retrieved from Prisma within

Trying to work with mapping a JSON object in a Next.js class component using data from Prisma. I've had to stringify the data from Prisma to avoid a serialization error on the date parameter. I know I can't directly use .map on this.props.commen ...

Troubleshooting HTML Output Display Issues

I've been trying to post my content exactly as I submit it, but for some reason, it's not working. When I enter two paragraphs in a post, the output doesn't maintain that formatting. Instead, it removes the paragraph breaks and displays the ...

JSfiddle not loading properly on website

I am facing an issue with my Jsfiddle code. It works correctly there, but when I copy it into my webpage along with the CSS and JavaScript files, it doesn't work. Can anyone provide insight on how to properly transfer the code to display it correctly ...

How come my deployment of a React app on Netlify is failing with exit code 1?

After numerous attempts to deploy my React project on Netlify, I still couldn't find a solution for the error I encountered. Below is the log that shows where things went wrong. (...) 12:21:05 PM: $ npm run build 12:21:06 PM: > <a href="/cdn- ...

There seems to be a problem retrieving the JSON file

My JavaScript file is designed to fetch a JSON file and execute a function if successful. If there's an error, it should display an alert window with the message "error". However, despite checking the syntax, I keep receiving an error alert every time ...

Ways to ensure CSS affects icon inside main element?

Struggling to match the background color of Material-UI icons with the rest of the list items on hover. The CSS is not applying to both the icon and text despite styling the overall class (className= "dd-content-item"). Any assistance would be greatly appr ...

How do you transform data stored in map to string format?

The main objective is to take a large txt file and replace all words according to the information in a csv file. This process will generate a new txt file as well as a new csv file that shows the frequency of each word. I'm currently struggling with ...

What is the proper way to apply a custom format to a NumberFormat within a Material-UI TextField?

I'm currently working with a Mui Textfield and I want to be able to use custom formats that can be passed as a prop. My challenge is figuring out how to pass these custom formats effectively. I came across an online sandbox that showcases the usage of ...