This question already has an answer here:
- Do I need to import React for stateless functional components? 2 answers
i am learning React js in case ii App.js module i have to import React because the render() method is used to convert JSX to dom elements how ever in Person.js we are creating a arrow function and we are exporting it so that it can be imported and used in the App modules render function how ever in App module we have React imported and it will convert the JSX in module person and gets rendered on DOM but when it throws an error when we remove the below code in Person.js
import React from 'react' in Person.js
it throws error
React' must be in scope when using JSX if we declare JSX in the methods (like render ) provided from React class it should give an error.
can someone please explain
i)why do we need to import react in Person.js?
ii)why was it throwing error when we remove the above code?
case i)
Person.js
import React from 'react'
const person = () => {
return <p>This is person module used inside app module</p>
};
export default person
case ii)
App.js
import React, { Component } from 'react';
import './App.css'
import Person from './Person/Person'
class App extends Component {
render() {
return (
<div className="App">
<h1>this is app module and i am being used as the root component</h1>
<Person/>
</div>
);}}
export default App;