I really need your help here, as I am new learning React. Meanwhile, this question has not yet been asked and the issue is not yet raised.
I am trying to call a to display on a element id using document.getElementById(‘disp’).innerHTML. However, I am having a [OBJECT OBJECT] response as the result if I use the component as a variable, and a gibberish of JSX webhook codes if I use it as a
Please help me with the following codes below and the screenshots explains my point.
injex.js
import ReactDOM from "react-dom/client";
import React from 'react'
import Nav from './Navigation'
import './styles.css'
import Logo from './logo1.png';
const Template = () => {
return (
<>
<section className='container-fluid'>
<header className='row bg-dark' style={ {height: '100px' }}>
<HeaderLogo />
<HeaderLeftColumn />
<HeaderRightColumn />
</header>
<sesion className='container-fluid'>
<section className="row">
<div className="col-sm col-mr col-md col-lg col-xl">
<HeaderMarquee />
</div>
</section>
</sesion>
<article className='container-fluid' id='disp' style={ {borderStyle: 'outset', borderColor: 'silver', borderRadius: '5px'} }>
<MainBody />
</article>
<div className='container-fluid'>
<div className='container'>
<div id='statusBar' className='alert'>...</div>
</div>
</div>
</section>
</>
)
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Template />);
Navigation.js
import React from 'react'
import "bootstrap/dist/css/bootstrap.min.css"
import './styles.css'
import CreateSchoolCategory from './components/createschoolcategory'
//this code works well when a text is just assigned to the div element
const showPaymentAPIPage = () => {
{ document.getElementById('disp').innerHTML = `Payment API Page` }
}
//calling it as a component will return [object object] as response on the element id
const showCreateSchoolCategory = () => {
{{ document.getElementById('disp').innerHTML = <CreateSchoolCategory /> } }
}
//calling it as a variable will return a gibberish of JSX interpreted codes on the element id.
const showCreateSchoolCategory = () => {
{{ document.getElementById('disp').innerHTML = CreateSchoolCategory } }
}
const Nav = () => {
return (
<>
{/* <section className='text-danger'> <TestPage /> </section> */}
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<button className="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span className="navbar-toggler-icon"></span>
</button>
<div className="collapse navbar-collapse" id="navbarSupportedContent">
<ul className="navbar-nav mr-auto">
<li className="nav-item dropdown">
<a className="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Main | Data Settings
</a>
<div className="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a className="dropdown-item listFont" href="#" onClick={showPaymentAPIPage}>Payment API</a>
<a className="dropdown-item listFont" href="#" onClick={showCreateSchoolCategory}> Create School Categories</a>
</div>
</li>
</ul>
</div>
</nav>
</>
)
};
export default Nav
createschoolcategory.js
import React, { Component } from 'react'
function headerText() {
// const url = window.location.href;
// if(url.includes('create-school-categories') === true){
// return document.getElementById('header').innerHTML = `Create New School Category`;
// }
// return document.getElementById('header').innerHTML = '';
return document.getElementById('header').innerHTML = `Create New Teacher Category`;
const CreateSchoolCategory = () => {
headerText()
return (
<>
<div className='container' id="disp">
<div className='row'>
<div className='col-sm col-md col-lg col-xl'>
<h5 className='text-info'>Create School Categories</h5>
</div>
</div>
</div>
</>
)
}
export default CreateSchoolCategory
Please help me!



