Having Issues with Material-UI Lists Rendering?

I am having an issue with rendering a list of posts on the index page. I can successfully create posts by clicking the 'Add Post' button and submitting the form on the /posts/new route. However, the list of posts is not showing up on the index page and there are no error messages displayed. Can someone please review my renderPosts method in the PostsIndex component and provide guidance on how to fix this issue? Thank you!

NETWORK

https://i.stack.imgur.com/M1V5x.png

ROOT INDEX

import ReactDOM from "react-dom";
import "./index.css";
import PostsIndex from "./containers/PostsIndex";
import PostsNew from "./containers/PostsNew";
import PostsShow from './containers/PostsShow';
import * as serviceWorker from "./serviceWorker";
import { Route, BrowserRouter, Switch } from "react-router-dom";
import { Provider } from "react-redux";
import { createStore, applyMiddleware } from "redux";
import reducers from "./reducers";
import promise from "redux-promise";

const createStoreWithMiddleware = applyMiddleware(promise)(createStore);

ReactDOM.render(
    <Provider store={createStoreWithMiddleware(reducers)}>
        <BrowserRouter>
            <div>
                <Switch>
                    <Route path="/posts/new" component={PostsNew} />
                    <Route path="/posts/:id" component={PostsShow} />
                    <Route path="/" component={PostsIndex} />
                </Switch>
            </div>
        </BrowserRouter>
    </Provider>,
    document.getElementById("root")
);
serviceWorker.unregister();

APP

import React, { Component } from 'react';
import MuiThemeProvider from '@material-ui/core/styles/MuiThemeProvider';
import PostsIndex from './containers/PostsIndex';
import './App.css';

class App extends Component {
    render() {
        return (
            <MuiThemeProvider>
                <div>
                    <PostsIndex />
                </div>
            </MuiThemeProvider>
        );
    }
}

export default App;

POSTS INDEX

import React, { Component } from "react";
import { connect } from "react-redux";
import { fetchPosts } from "../actions/index";
import { bindActionCreators } from "redux";
import { Link } from 'react-router-dom';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemText from '@material-ui/core/ListItemText';
import _ from "lodash";

class PostsIndex extends Component {
    componentDidMount() {
        this.props.fetchPosts();
    }

    renderPosts = () => {
        return _.map(this.props.post, post => {
            return (
                <Link to={`/posts/${post.id}`}>
                    <List>
                        <ListItem key={post.id}>
                            <ListItemText primary={post.title}/>
                        </ListItem>
                    </List>
                </Link>
            );
        });
    };

    render() {
        return (
            <div>
                <h1>Blog About It</h1>
                <Link to="/posts/new">Add Post</Link>
                <List>
                    <ul>{this.renderPosts()}</ul>
                </List>
            </div>
        );
    }
}

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

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

export default connect(
    mapStateToProps,
    mapDispatchToProps
)(PostsIndex);

Answer №1

Unfortunately, I am unable to leave a comment so I will attempt to provide an answer instead,

When looking at the code snippet provided, it seems that the function renderPosts is utilizing this.props.post, however, based on the implementation in your mapStateToProps method, it appears that it should actually be referring to this.props.posts.

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

Encountering issues with retrieving application setting variables from Azure App Service in a ReactJS TypeScript application resulting in '

My dilemma lies in my app setup which involves a Node.js runtime stack serving a ReactJs Typescript application. I have set some API URLs in the application settings, and attempted to access them in ReactJs components using process.env.REACT_APP_URL, only ...

Guide on implementing gradient animation effects in a React component

How can I implement gradient animation effects like this example in a React component using inline CSS? I need to utilize the CSS-based gradient animation effects shown below directly within the React component. Are there any specific packages available ...

Personalized Input Field using Material Design UI

Looking to personalize the TextField component in React Material UI, particularly focusing on the following CSS class? root: { '& .MuiOutlinedInput-inputMarginDense': { paddingBottom: 'none !important', }, }, &l ...

React: Unexpected behavior when modifying a variable's state using post-increment

When I utilize the post-increment operator to change the state variable, the count variable retains its old value... Allow me to illustrate this with an example app: When I click the button with the following code, the app displays the following sequenc ...

Semantic-ui-react cannot be located by Docker

I am a beginner when it comes to docker and I'm looking to create a React app, specifically using TypeScript, inside a docker container. In order to do this, I need to incorporate semantic-ui-react into my project. I followed the instructions provide ...

Encountering an issue with running npm build? Receiving an error related to

Running npm start command [email protected] starting the application using react-scripts An issue has been detected with the project dependency tree. While this may not be a bug in Create React App, it is something that needs to be addressed locall ...

When a parameter is passed into a React-Query function with an undefined value, it can lead to the API returning a 404 error

Two parameters are sent from the frontend to trigger a GET request in another TypeScript file. It seems that one of the parameters is not successfully passed due to unknown rerenders, resulting in a 404 Error being returned by the API call in the console. ...

Prevent backspace and delete keys from functioning in a column of a DataGrid using material-ui

Does anyone have a solution for disabling the backspace and delete keys in a column when using DataGrid with material-ui? ...

Tips for transforming Material UI style helpers with Jest

Currently, I am in the process of writing Jest unit tests for ReactJS components that are utilizing Material UI's makeStyles. Majority of the tests are passing without any issues; however, an error regarding Unexpected token is being thrown specifica ...

Is it possible to utilize a React component within the DataGrid cell instead of the standard cell types like 'string', 'number', 'date', and 'dateTime' in Material UI?

Using React, Material UI, and TypeScript I am trying to embed a React component into the cell of a DataGrid but have encountered an issue. I have explored custom column types for cells here, however, it only allows me to manage string formats, whereas I ...

Sending out the instruction to handle changes in state with

In my redux action, I have one action being called by two other actions. Here is the code snippet: export const addParticipantFromPopupRequest = (participant, project_id, currentStep) => async (dispatch) => { const result = await addParticipant(p ...

Can you explain the concept of "pre-rendering a page before a user makes a request"?

Currently, I'm diving into Next.js and exploring the distinction between static generation and server-side rendering (SSR). While reading through their documentation, one sentence caught my attention: "On the other hand, Static Generation is not a goo ...

Problem: The Material UI Dialog component is causing the window scroll to be hidden

Whenever a window scroll is visible on any page, opening the material-ui dialog control hides the scroll and causes the page to shake as it adjusts its width and height. Upon closing the dialog, the scroll reappears, causing the page to shake once again. I ...

React-query v5 - Updating or fetching outdated query

I am currently using the Tanstack/react-query v5.12.2 library and I am facing an issue with invalidating or refetching an inactive query using the useQueryClient() function. It seems that something has changed in version 5 of the library. I have tried sett ...

An issue with the updating process in React Native's useState function

I am currently facing a challenge with an infinite scroll listview in react native. I have created a calendar list that needs to dynamically change based on the selected company provided as a prop. The issue arises when the prop (and the myCompany state) a ...

What is causing my fetch response to not be passed through my dispatch function?

I'm currently utilizing a node server to act as the middleman between firebase and my react native app. Could someone kindly point out what might be going awry in my fetch method below? export const fetchPostsByNewest = () => { return (dispatch ...

The design of Next.js takes the spotlight away from the actual content on the

Recently, I've been working on implementing the Bottom Navigation feature from material-ui into my Next.js application. Unfortunately, I encountered an issue where the navigation bar was overshadowing the content at the bottom of the page. Despite my ...

What is the best way to trigger a function in React when a constant value is updated?

In my React application, I have 3 components. The parent component and two child components named EziSchedule and EziTransaction. Each component fetches its own data from an API. The data to display in the EziTransaction child component depends on the reco ...

Would it be beneficial to host a React application on Apache web server?

We understand that the standard method is to use node.js, but our server-side API is built on Apache. Therefore, we prefer to stick with Apache. Can React be run effectively on Apache without needing to install node.js? For setting up .dotenv pack ...

Is it possible to customize the color of icons in react's Material-table?

I'm currently utilizing the material-table library and I'm struggling to individually change the color of each icon. Could you assist me with this? I attempted custom CSS, but it's affecting all icons at once instead of specific ones. Here i ...