Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null [closed]

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; 
like image 582
pKay Avatar asked Oct 14 '17 05:10

pKay


People also ask

Was returned from render this usually means a return statement is missing or to render nothing return null?

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 .

Which of the following when returned from a react component would render nothing?

If you return null from a component, nothing is rendered. You can also return null to render nothing from a JSX expression.

What does render method return?

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.

Can I return undefined from render function in react?

We cannot include undefined because it would throw an error at runtime.


1 Answers

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

like image 107
devsourav Avatar answered Sep 20 '22 20:09

devsourav