Page Content Fails to Load Without Reloading

I am currently working on a simple project using React with TypeScript, and I have run into an issue where the page content does not refresh as expected without having to reload the page. I am unsure of the underlying cause of this behavior. I have included a breakdown of the project files and code. Any assistance in resolving this issue would be greatly appreciated. Please help me rectify this problem.

App.tsx

import React from 'react'
import './App.css';
import Menu from './Menu';
import { BrowserRouter, Route, Switch } from 'react-router-dom';
import routes from './route-config';

function App() {
  return (

    <BrowserRouter>
      <Menu />
      <div className='container'>
        <Switch>
          {
            routes.map(route=>
              <Route key={route.path} path={route.path} exact={route.exact}>
                <route.component/>
              </Route>
              )
          }
        </Switch>
      </div>
    </BrowserRouter>
  );
}

export default App;

route-config.tsx

import CreateGenre from "./component/genres/CreateGenre";
import EditGenre from "./component/genres/EditGenre";
import IndexGenres from "./component/genres/IndexGenres";
import LandingPage from "./component/movies/LandingPage";

const routes = [
    {path:'/genres',component:IndexGenres, exact:true},
    {path:'/genres/create',component:CreateGenre},
    {path:'/genres/edit',component:EditGenre},
    {path:'/',component:LandingPage, exact:true}

]

export default routes;

Menu.tsx

import React from 'react'
import { NavLink } from 'react-router-dom'

const Menu = () => {
  return (
    <nav className='navbar navbar-expand-lg navbar-light bg-light'>
        <div className='container-fluid'>
            <NavLink to="/" className='navbar-brand'>React Movies</NavLink>
            <div className='collapse navbar-collapse'>
                <ul className='navbar-nav me-auto mb-2 mb-lg-0'>
                    <li className='nav-item'>
                        <NavLink className='nav-link' to="/genres">
                            Genres
                        </NavLink>
                    </li>
                </ul>
            </div>

        </div>
    </nav>
  )
}

export default Menu

LandingPage.tsx

import React, { useEffect, useState } from 'react'
import MoviesList from './MoviesList'
import { landingPageDTO } from './movies.model'

const LandingPage = () => {
    const [movies, setMovies] = useState<landingPageDTO>({})
  useEffect(() => {
    const timerId = setTimeout(() => {
      setMovies({
        inTheaters: [
          {
            id: 1,
            title: 'Spider-Man: Faar From Home',
            poster: 'https://upload.wikimedia.org/wikipedia/en/b/bd/Spider-Man_Far_From_Home_poster.jpg'
          },
          {
            id: 2,
            title: 'Luca',
            poster: 'https://upload.wikimedia.org/wikipedia/en/thumb/3/33/Luca_%282021_film%29.png/220px-Luca_%282021_film%29.png'
          }
        ],
        upcomingReleases: [
          {
            id: 3,
            title: 'Soul',
            poster: 'https://upload.wikimedia.org/wikipedia/en/3/39/Soul_%282020_film%29_poster.jpg'
          }
        ]
      })
    }, 1000)
    return () => clearTimeout(timerId)
  },[])
  return (
    <>
        <h3>In Theatres</h3>
        <MoviesList movies={movies.inTheaters} />

        <h3>Upcoming Release</h3>
        <MoviesList movies={movies.upcomingReleases} />
   
    </>
  )
}

export default LandingPage

Onclick change content without any reload.

Answer №1

Resolved the issue with React 18 by reverting back to React 17. Everything is functioning smoothly now.

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

Unveiling the Secrets of Implementing Interactive HTML Tabs

I have a simple HTML page that contains a table with two columns and two rows. My goal is to convert these two columns into tabs, so that when each row is clicked, it will display either a paragraph or another basic table with one row and column. All of t ...

Responsive Design and Advertising with CSS Media Queries

For my application, I am utilizing Twitter's bootstrap (responsive) css. My goal is to incorporate banner ads in the sidebar section. However, due to different media query settings, the sidebar's width will vary, resulting in the need for the ban ...

What other options are available besides componentDidUpdate for retrieving the chosen date from a date picker and including it in an API request?

Currently, I am utilizing react-dates to implement a datepicker feature. Whenever the user modifies the date, it updates a prop that is then sent to the backend as a parameter in a query to fetch specific results for that particular day from the database. ...

Error encountered: _moment2.default.date is not a recognized function within the React application

I keep encountering an issue when attempting to utilize a date from Moment.js in the constructor, componentWillMount, or componentDidMount. The error message I receive is: Uncaught TypeError: _moment2.default.date is not a function It's worth noting ...

Steps to assign a JSON file to an array within an object in Angular

What is the best way to assign a JSON file to an array within my "Client" object? I currently have a JSON file named Clients.json with the following structure: { "clients": [ { "firstName": "nameA", "lastName": "lastA", "doctorsNam ...

Using Multiple CSS Loaders in Webpack

I'm currently facing an issue with loading bootstrap CSS for use within my webpack application. The problem arises from the fact that I have a CSS loader in place with localIndentName for component-specific CSS to prevent naming conflicts with other c ...

Switch the background color when a radio button is chosen

For my quiz on test practice with an array of questions, each question includes five radio buttons, but only one is correct. Initially, all five options have a gray background. Upon selecting a wrong option, it changes to red. If another incorrect option i ...

Converting a List of Maps from Immutable.js into a List of Lists and utilizing it as the dataset for Google Charts

I am currently working on implementing the Google Charts library to visualize some time series data. Right now, I have dummy data stored in a separate file from my application. In this file, I have an Immutable List structured like this: le ...

Issues with aligning div elements centrally

I have a dilemma with aligning two divs on my webpage. I am trying to position the second div in such a way that it is centered between the first div and the end of the page, like this: | | | | | | | | | | | | | | div1 | ...

After modifying the template, the ReactDOM.render() function fails to work when called again

Initially, the render() function works perfectly. However, upon calling it again through one of the event handler functions, it fails to work. The Chrome DevTools console does not show any errors. The changes are made within the options array and then nee ...

Tips for positioning and resizing images within a changing DIV dimension

My DIV element is adjusting its size based on the browser window. Inside this DIV, there is an image that should fill up the entire browser window without stretching out of proportion when the window dimensions change. In addition, I want the image to be ...

Eliminate the loading screen in Ionic 2

Within my app, there is a button that triggers the opening of WhatsApp and sends a sound. Attached to this button is a method that creates an Ionic loading component when clicked. The issue I am facing lies with the "loading.dismiss()" function. I want the ...

Disregarding boundaries set by divisions

Trying to keep things concise here. I have a division called "the box" with a fixed width of 1200px that contains various other divisions. One of these divisions is a links bar, known as the "pink bar", which has a width of 100% and a height of 25px. My is ...

Typescript function incorrectly returns Protractor's "element.all" output as Promise<string> instead of Promise<string[]>

Kindly review the code snippet provided below. The function getAllGroupIds() is designed to return an array of IDs belonging to "group" elements. The goal is to retrieve all the group-ids both before and after a test action, in order to compare them. Howe ...

Issue with maintaining fixed space above navbar in HTML/CSS code

I'm struggling to make my navbar sticky on my website without any space above it. Can someone help me with this issue? Here is the URL to my site: My CSS looks like this: body { font-size: 12px; line-height: 22px; font-family: Arial, H ...

What are the potential drawbacks of using this alternative method instead of `useCallback` in React to prevent unnecessary re-renders of children components?

While exploring some code, I stumbled upon an alternative method to prevent function recreation during renders compared to the official useCallback hook. This method seems to offer certain benefits over useCallback, but I am interested to know if there are ...

What is the best way to show specific links in the navigation bar only when the user is signed in using Angular?

I'm attempting to customize the navigation bar to display "Sign In" and "Sign Up" buttons only when the user is not signed in, and show the message and profile navigation items when the user is signed in. Below is the provided code snippet: Token Se ...

Error TS[2339]: Property does not exist on type '() => Promise<(Document<unknown, {}, IUser> & Omit<IUser & { _id: ObjectId; }, never>) | null>'

After defining the user schema, I have encountered an issue with TypeScript. The error message Property 'comparePassword' does not exist on type '() => Promise<(Document<unknown, {}, IUser> & Omit<IUser & { _id: Object ...

Tips on monitoring the activities of various verified users through Mixpanel

After successfully building a React application, I realized the importance of user authentication through Auth0. In addition, I integrated Mixpanel to track various events within the application using commands like mixpanel.track('Click event A') ...

Understanding the Usage of FormData in NextJS

I'm trying to read fetch's body contents. Here's the code I'm using: fetch('/api/foo', { method: 'POST', body: new FormData(formRef.current), }); https://i.sstatic.net/6YB1V.png Now I need to parse the body dat ...