The React CSS seems to be functioning properly on Desktop Site, but unfortunately, it does not show up on mobile devices using Chrome, Safari

As a newcomer to ReactJS, I welcome any advice that can be provided

  • I've developed and deployed my ReactJS app on Heroku
  • It's working perfectly on desktop browsers (Chrome, Firefox, Safari) but not displaying correctly on mobile (iPhone 7) and tablet devices.

I humbly ask for assistance in identifying the possible reason for this issue. The console does not show any errors.

https://i.sstatic.net/wa2rM.jpg

app/public/index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="theme-color" content="#000000">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json">
    <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;800&display=swap" rel="stylesheet">
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-X"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'UA-XXXXXXXXX-X');
    </script>
    <title>App | REACT App</title>
  </head>
  <body>
    <noscript>
      You need to enable JavaScript to run this app.
    </noscript>
    <div id="root"></div>
  </body>
</html>

app/scr/App.js

import React, { Component } from 'react';
import { BrowserRouter, Switch, Route } from 'react-router-dom';
import Layout from './components/Layout/Layout'
import Footer from './components/Footer/Footer';
import Home from './components/Pages/Home';
import BlogIndex from './containers/BlogBuilder/BlogIndexBuilder';
import BlogShow from './containers/BlogBuilder/BlogShowBuilder';

class App extends Component {
  render() {
    return (
      <BrowserRouter>
        <div className="App">
          <Layout>
            <Switch>
              <Route exact path="/blogs" component={BlogIndex} />
              <Route path="/blogs/:id" component={BlogShow} />
              <Route path="/" component={Home} />
            </Switch>
            <Footer />
          </Layout>
        </div>
      </BrowserRouter>
    );
  }
}

export default App;

app/src/containers/BlogBuilder/BlogIndexBuilder.js

import React, { Component } from 'react';
import BlogIndex from '../../components/Blog/Index';
import axios from 'axios';

class BlogIndexBuilder extends Component {
  state = {
    posts: []
  };

  componentDidMount() {
    axios
      .get(
        "http://public-api.wordpress.com/rest/v1/sites/xxxxx.wordpress.com/posts"
      )
      .then(res => {
        this.setState({ posts: res.data.posts });
        console.log(this.state.posts);
      })
      .catch(error => console.log(error));
  }

  parseOutScripts(content) {}

  render() {
    return (
      <div>
       <BlogIndex 
        posts={this.state.posts}
       />
      </div>
    );
  }
}

export default BlogIndexBuilder;

app/src/components/Blog/Index.js

import Layout from '../../components/Layout/Layout';
import Header from '../../components/Header/Header';
import { Link } from 'react-router-dom';
import './Index.css';
import BlogBanner from '../../images/img-blog-banner.png';
import Moment from 'moment';
    
    class Index extends Component {
      removeUnicode(string) {
        if (string.indexOf("&#8211;") >= 0) {
          return this.removeUnicode(string.replace("&#8211;", "'"));
        } else {
          return string.replace("<p>", "").replace("[&hellip;]</p>", "...");
        }
      }
    
      render() {
        return(
          <Layout>
            <div className="blog_index_section">
              <Header />
              <div>
                  <ul>
                    {this.props.posts.map((post) => {
                      if (post) {
                        return(
                          <li key={post.ID} className="card">
                            <Link to={`/blogs/${post.ID}`}>
                              {post.featured_image ? (
                                <img alt="blog header" src={post.featured_image} />
                              ) : (
                                <img src={BlogBanner} alt="BlogBanner"/>
                              )}
                              <div>
                                <div>{post.title}</div>
                                <div>{this.removeUnicode(post.excerpt)}</div>
                              </div>
                            </Link>
                          </li>
                        );
                      } else {
                        return null;
                      }
                    })}
                  </ul>
              </div>
    
            </div>
          </Layout>
        );
      }
    }
    
    export default Index;

Answer №1

Resolved the issue.

An error message appeared in the console:

Cross-origin redirection to https://public-api.wordpress.com/rest/v1/sites/xxx.wordpress.com/posts denied by Cross-Origin Resource Sharing policy: Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin.

XMLHttpRequest cannot load http://public-api.wordpress.com/rest/v1/sites/xxx.wordpress.com/posts due to access control checks.

This error only seems to occur in Safari.

SOLUTION to fix this error: How to overcome the CORS issue in ReactJS

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

Executing a Function Prior to onClick Event of a Link Element in Next.js

While working on a slider/carousel, I encountered an issue. Each photo in the slider should be draggable back and forth, with a click taking the user to a product page. I am using next.js with react-flickity-component for this purpose. Please note that thi ...

Shifting from Redux to React-Query: A step-by-step guide

I am currently delving into react-query but I find it quite challenging to grasp. Can someone please provide an example based on the code snippet below? The following code includes an action and a reducer: export const addHighlighting = parent_id => di ...

Incorporating a splash of color while changing the background color on scroll

Is it possible to include more colors between the "beginning-color" and the "ending-color" in this code that changes the background color on scroll? example $(document).ready(function(){ var scroll_pos = 0; var animation_begin_pos = 0; ...

Instructions on setting a photo as a background image using a text-based model

I'm a beginner with Angular so I may have a simple question. I am using an image from the Google API, which is not a URL. How can I set this image as the background-image in a CSS tag that only accepts URIs? Thank you! ...

Toggle the visibility of radio buttons by displaying a hidden div class instead. When the div is clicked, automatically select

I'm attempting to make this functionality work differently. Instead of displaying the standard radio button, or replacing it with an image, I want to use a styled div as a button. When hovered over, the class should change, and when clicked, the class ...

Issue with state not being properly updated in a separate component within React/Next.js framework

Having an issue I am in the process of creating a cart feature and have encountered an issue in my main _app.js file, essentially the index.js file for react where I am utilizing the useState hook. The problem arises when I pass a function to update a va ...

Adding custom script tags to a React application

I'm interested in integrating a StreamingVideoProvider video player into my React application but facing some challenges: I do not have direct access to the video URL I want to utilize their JS video player for its advanced features like password pro ...

Struggling to access the input field in material UI components using refs in ReactJS

Currently, I am working on a Web application using React JS + Material UI core. My task involves building a form with material ui controls, specifically TextField. When attempting to retrieve the input field value using refs in React, I consistently encoun ...

What is the best way to dynamically adjust the height of an iframe based on its changing content

My webpage contains an iframe that loads content dynamically, and I want to center it on the page based on its height. The issue I'm facing is that while my code works well for increasing content heights, it fails to recognize when the content size de ...

Error message in React: "Module './assets/photo.jpg' not found"

Encountering an error that says "Cannot find module './assets/photo.jpg'". This is the code snippet in app.js import ReactDOM from 'react-dom'; import './App.css'; import Intro from './components/Introduction' func ...

Creating an enum from an associative array for restructuring conditions

Hey everyone, I have a situation where my current condition is working fine, but now I need to convert it into an enum. Unfortunately, the enum doesn't seem to work with my existing condition as mentioned by the team lead. Currently, my condition loo ...

When utilizing Typescript to develop a form, it is essential to ensure that the operand of a 'delete' operator is optional, as indicated by error code ts(279

Can someone help me understand why I am encountering this error? I am currently working on a form for users to submit their email address. export const register = createAsyncThunk< User, RegisterProps, { rejectValue: ValidationErrors; } > ...

What is the process of moving an event (action) from an internal component to an external one in reactjs

If my layout is structured like this: -- App -- List -- Item I want to be able to select only one item at a time, making the others disabled. How can I pass the event from the Item component to the App component? Example: /* In App */ handleC ...

Adjusting the background color of a MuiList within a React Material-UI Select component

Looking to customize the background color of the MuiList in a react material-ui Select component without affecting other elements. Specifically targeting the Select element with the name 'first'. Despite setting className and trying different cl ...

Utilizing jQuery to delete items once their corresponding checkboxes are checked

I have successfully implemented a feature where I can add more fields by clicking a button. However, I am facing an issue when trying to delete a field after checking the checkbox. Any assistance on this matter would be greatly appreciated. jQuery: $(doc ...

Is it possible to design a genuinely unique component with MUI?

Is it possible to create a custom MUI component called MyCustomButton that can be tailored using theme configurations, such as setting muiName = 'MyCustomButton'? The desired customization would involve defining styles for the root element and an ...

Ensuring maximum length validation on input

I am having an issue with the function "checkNumbers()". I am attempting to validate if my input does not exceed 10 numbers; while "isAllowedSymbol()" is functioning correctly, the other one is not. What could be causing this problem? function isAllowe ...

What is the best way to incorporate two different CSS styles for two separate images within HTML pages?

Looking for some assistance here! I'm trying to figure out how to incorporate two different CSS styles for two separate images on an HTML page, with a vertical space between them. Check out the paintings below. They each have unique sizes and styles ...

Enhance the performance of jQuery and CSS on your WordPress site

I'm currently working on a WordPress 4.3 website that utilizes over 20 plugins, each loading CSS and jQuery on every page. My main concern is how to optimize the styles and jQuery so that only the necessary ones are loaded on each page. I've at ...

Maintaining nth-child(odd) following filtering using jQuery

I am using a jQuery script to filter a table with multiple entries on this site. The filtering works well, but the issue arises when it comes to maintaining the correct tr:nth-child(odd) color that I have specified in my CSS. After filtering, the original ...