I have a component in React which I am importing in index.js, but it is giving this error:
Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null
index.js:
import React from 'react'; import ReactDOM from 'react-dom'; import Search_Bar from './components/search_bar'; const API_KEY = 'AIzaSyCnpDObOLiiqN87YKJKZ-cxzdAsvYD1F-U'; const App = () => { return ( <div> <Search_Bar /> </div> ); } ReactDOM.render(<App />, document.querySelector('#root'));
component:
import React from 'react'; const Search_Bar = () => { return <input />; }; export default Search_Bar;
Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null. This warning happens when you're missing a return statement in your render function, or you attempt to return early, but return void via return; instead of returning null .
If you return null from a component, nothing is rendered. You can also return null to render nothing from a JSX expression.
Purpose of render(): React renders HTML to the web page by using a function called render(). The purpose of the function is to display the specified HTML code inside the specified HTML element. In the render() method, we can read props and state and return our JSX code to the root component of our app.
We cannot include undefined because it would throw an error at runtime.
I had same problem in the render() method. The problem comes when you return from render() as :
render() { return ( <div>Here comes JSX !</div> ); }
i.e. if you start the parenthesis in a new line
Try using:
render() { return ( <div>Here comes JSX !</div> ); }
This will solve the error
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With