i’ve a react component that i import, but its not displayed on the page.
this is my app.js file. i imported the "functionalComponent" component but it is not getting displayed on the browser.
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import functionalComponent from './functionalComponent';
import classComponent from './classComponent';
function App() {
return (
<div className="App">
<functionalComponent/>
</div>
);
}
export default App;
This is my functionalComponent.js
import React from "react";
class functionalComponent extends React.Component{
render(){
return <p>This is a functional component.</p>
}
}
export default functionalComponent;
and this is my App.test.js
import { render, screen } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
3
Answers
This is how a function component should look like, just like your
App
component, in your example you are using a classReact requires that the first letter of components be capitalized
change your component name to FunctionalComponent and check if this fixes the issue.
Thanks
the component name should be FunctionalComponent, not functionalComponent. JavaScript is case-sensitive, so the incorrect casing prevents the component from being recognized.
In functionalComponent.js:
import React from "react";