I'm developing a map functionality using ReactJS
, My app.js
file is:
import React, { Component } from 'react';
import './Map';
class App extends Component {
render() {
return (
<div className="App">
<Map/>
</div>
);
}
}
export default App;
The error is:
./src/App.js
Line 8: 'Map' is not defined react/jsx-no-undef
Search for the keywords to learn more about each error.
How can I solve this problem?
This question is related to
javascript
reactjs
its very similar with nodejs
var User= require('./Users');
in this case its React:
import User from './User'
right now you can use
return (
<Users></Users>
)
Strangely enough, the reason for my failure was about the CamelCase that I was applying to the component name. MyComponent
was giving me this error but then I renamed it to Mycomponent
and voila, it worked!!!
in map.jsx
or map.js
file, if you exporting as default like:
export default MapComponent;
then you can import it like
import MapComponent from './map'
but if you do not export it as default like this one here
export const MapComponent = () => { ...whatever }
you need to import in inside curly braces like
import { MapComponent } from './map'
like below:
import './css/app.css'
if you are using sass all you need to do is just use sass loader with webpack!
Here you have not specified class name to be imported from Map.js file. If Map is class exportable class name exist in the Map.js file, your code should be as follow.
import React, { Component } from 'react';
import Map from './Map';
class App extends Component {
render() {
return (
<div className="App">
<Map/>
</div>
);
}
}
export default App;
should write like this -->
import Map from './map';
Map
should have first later is capital .(important note)You have to tell it which component you want to import by explicitly giving the class name..in your case it's Map
import Map from './Map';
class App extends Component{
/*your code here...*/
}
you should do import Map from './Map'
React is just telling you it doesn't know where variable you are importing is.
Source: Stackoverflow.com