`finding difficulty in presenting components in react`

I am encountering issues with an outdated version of CRUD where some codes are no longer functioning as expected. Visual Studio Code does not flag them as errors, so the page continues to load but my content box remains empty. Can someone assist me with this?

There are 4 codes that I believe need improvement...

First, my header is not displaying the props.icon tasks

import './Header.css'

import React from 'react'

export default function props () {
  return (
    <header className = "header d-none d-sm-flex flex-column">
      
      <h1 className="mt-3">
        <i className={`fa fa-${props.icon}`}></i>{props.title}
      </h1>
  <p className="lead text-muted">{props.subtitle}</p>
    </header>
  )}

Next, my main.jsx contains the import for my header

import './Main.css'
import React from 'react'
import Header from './Header'

function props () {
    return (
    <React.Fragment>
        <Header {...props}/>
        <main className="content container-fluid">
        <div className="p-3 mt-3">
            {props.children}
        </div>
        </main>
    </React.Fragment>
    )    
}
    
export default props

Now, my app.jsx and app.css render my HTMLs

import 'bootstrap/dist/css/bootstrap.min.css'

import 'font-awesome/css/font-awesome.min.css'

import './App.css'

import React from 'react'

import {HashRouter} from 'react-router-dom'

import Routes from './Routes'

import Logo from '../components/template/Logo'

import Navi from '../components/template/Navi'

import Footer from '../components/template/Footer'

function Props () {

    return(

    <HashRouter>

        <div className="App">

            <Logo />

            <Navi/>

            <Routes/>

            <Footer /> 

        </div>

        </HashRouter>

    )

}



export default Props

//////////////////////////

:root{

    --bg-dark: #1a2f3a;


    --logo-height: 100px;

    --header-height: 100px;
    ...
    }

Then, my routes.jsx

import React from 'react'
import {Switch, Route, Redirect} from 'react-router'

import Home from '../components/home/Home'
import UserCrud from '../components/user/UserCrud'

function Props (){
    return(
    <Switch>
        <Route exact path="/" component={Home}/>
        <Route path="/users" component={UserCrud}/>
        <Redirect from="*" to="/"/>
    </Switch>
    )   
}

export default Props

Finally, my home component, which is associated with the main component and represents the '/' path

import React from 'react'
import {Switch, Route, Redirect} from 'react-router'

import Home from '../components/home/Home'
import UserCrud from '../components/user/UserCrud'

function Props (){
    return(
    <Switch>
        <Route exact path="/" component={Home}/>
        <Route path="/users" component={UserCrud}/>
        <Redirect from="*" to="/"/>
    </Switch>
    )   
}

export default Props

I have been trying to resolve this error for 2 days now, and I suspect it might be a syntax error. If you have expertise in this area, please share your insights.

I am seeing some console issues including warnings about

require("history").createMemoryHistory
and require("history").PathUtils. Additionally, there is a warning about componentWillMount being renamed. Any assistance in resolving these issues would be greatly appreciated.

Answer №1

It seems there may be some confusion about the role of props in React. I recommend taking a look at the documentation for a clearer understanding of how props are used to manage data flow in React apps.

In essence, props are like the inputs that components pass to each other to control the UI and application state. In functional React, they act as parameters that a component uses to produce a specific output in JSX.

In your code, simply naming functions as Props does not automatically provide access to the props. First, a parent component must pass a prop in the JSX, and then the receiving component must access that prop through the function parameters. Here's a simplified example to illustrate this concept:

// App.jsx

function App() {
  return (
    <div>
      <Header title={'someValue'}/>
      <MainComponent />
    </div>
  );
};

// Header.jsx

function Header(props) {
  return (
    <header>
      <h1>{props.title}</h1>
    </header>
  );
};

It looks like you also attempted to use props.children, which serves a different purpose and requires a different approach. The children of a component refer to any elements enclosed within the component at the time of declaration. While they are not passed as props in the traditional sense, they still need to be accessed through the function's parameters. In the following example, the props.children of MainComponent is the div with the class child:

// App.jsx

function App() {
  return (
    <div>
      <MainComponent>
        <div class="child">
        </div>
      </MainComponent>
    </div>
  );
};

// MainComponent.jsx

function MainComponent(props) {
  return (
    <main>
      {props.children}
    </main>
  );
};

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

Create a Bootstrap jumbotron that is centered and only half of the width

I have a unique password reset method here: Jumbotron-Form-Bootstrap-My-Attempt Displayed below is the code from the image above: <div class="container"> <div class="jumbotron"> <br><br> <h2>Forget Passwo ...

Is it necessary to scroll when all elements on the page are in absolute position?

I have all elements positioned absolutely on my page. Some are at the top and some are at the bottom. However, when I add an additional element to display news text in the center of the page, it gets hidden under the element aligned at the bottom. When I s ...

Swap out the div element with a loading.gif image right before the page finishes loading, then pause for 3 seconds before getting rid of

My challenge involves a select drop down that is being dynamically built. To handle this, I have implemented a setTimeout function to change the selected option after a 3-second delay. This allows the select element to load first before I manipulate it. Ho ...

Working with jQuery, CSS, and functions to modify the current tag's class

Let's keep it brief and straightforward: Here is my HTML <div id="headerVideoControls" class="overlayElement"> <div id="videoMuteUnmute" onclick="muteUnmuteVideo('headerVideo')">mute button</div> </div> Edited ...

How to Align Horizontal Scrollable Cards in Bootstrap 4

Having trouble centering a Single Row of Horizontal Scrolling Cards. I've tried: a) the mx-auto class b) using text-align: center Nothing seems to be working and there's a lot of space on the right side in desktop view. Interestingly, the scro ...

Add a prefix to every hyperlink in an HTML document

I'm looking to transfer an HTML template to a Google site using embedded code. The template includes a table with over 500 links that need to be prepended. Is there a method to achieve this without relying on JavaScript? <table class="wikitabl ...

Explore the interactive feature of hovering over a component within a div that is enhanced with a transformative translate3d effect upon hover. Discover the seamless event queuing

Within a div, there is a modal component that includes a transform: translate3d effect with hover transition. The div is created using vue.js list rendering method. Upon opening the modal and hovering over it, it jerks between the parent div and its intend ...

How can the color of unselected mat-steps be customized in Angular?

In my CSS code, I have specified the styling for the selected mat-step as follows: ::ng-deep .mat-step-header .mat-step-icon-selected { background-color: #a94442; } While this code works well, I encountered a need to update only certain blue icons: ...

Styling your text: Choosing the right font for an online editing tool

In the process of creating a web-based code editor, I have currently implemented the following rule for both line numbers and the source code: font-family : "Courier New", Courier, monospace I have a couple of questions regarding this choice: Will this ...

Is it possible to designate a specific font family for italic font style and a different font family for regular font styles in VSCode?

Is it possible to use the "Operator Mono" font only for italic style and another font, such as "Fira Code," for other styles like bold, regular, semibold, etc. in VSCode? I attempted to change the font family to: "editor.fontFamily": "'Operator Mono ...

Having trouble integrating a Bootstrap-based ecommerce theme into an Angular8 project?

I have a bootstrap-based ecommerce theme with all the necessary files. The HTML theme is loading perfectly. Check out the official theme page I am integrating into my angular8 project: Theme Page Link I have created a repository for my angular8 project ...

Arrange the contents within a div with Bootstrap 4 for proper alignment

Just stepping into the world of front end development and my question might come off as quite basic. Currently, I am delving into ReactJS. https://i.sstatic.net/o9tDo.png My current challenge is related to the following code snippet: <div className=" ...

When pressing the next or previous button on the slider, an error message pops up saying "$curr[action] is not a

I found this interesting Js fiddle that I am currently following: http://jsfiddle.net/ryt3nu1v/10/ This is my current result: https://i.sstatic.net/VygSy.png My project involves creating a slider to display different ages from an array, such as 15, 25, ...

IE and Chrome are experiencing issues where the radio buttons are disappearing

Here is the style sheet code: select,input ,td a {border:1px solid green; width:25%;height:25px;font-size:20px;margin- left:.1em;} input.myradio {border:none;width:0%;height:0%;font-size:0%;} And here is the corresponding HTML code: <td><inpu ...

How to align li elements at center in a Bootstrap navbar

I'm having trouble centering link1 and link2 both horizontally and vertically on the page. The horizontal alignment is working fine, but I can't seem to get the vertical alignment right, no matter what I try. Here is the HTML code snippet: ...

CSS: The element's relative size causes the background image to vanish

I am facing an issue with displaying a background-image that is 800x480 pixels. The background image appears when the element has a fixed size, but not when the element has a relative size or a max-width. Functional CSS code: .audio-container, .settings- ...

Is it possible to iterate through div elements using .each while incorporating .append within an AJAX call?

After sending AJAX requests and receiving HTML with multiple div elements (.card), I am using .append to add new .card elements after each request, creating an infinite scroll effect. However, I am facing issues when trying to use .each to iterate over all ...

Enhance design based on scrolling function in React

I've been trying to update the color of my header when a user scrolls the page, but for some reason, my onScroll method isn't working. Can anyone help me figure out why and how to solve this issue? The onScroll method is triggered by the bottom T ...

Is there a way to dynamically toggle the visibility of a floating textarea between on and off?

I have my own blog website: Essentially, what I am aiming for is When a user clicks on the search button, a floating semi-transparent textarea window should appear inside the designated rectangle area (as shown in the image, that red orange rectangle). ...

CSS3 Animation: Facing issue with forwards fill behavior in Safari when using position and display properties

After creating a CSS3 animation to fade out an element by adjusting its opacity from 1 to 0 and changing the position to absolute and display to none in the last frames, I encountered an issue. In Safari, only the opacity is maintained while the position a ...