ReactCompositeComponent.render(): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object

If you return an array for component, then you will get this error “Uncaught Invariant Violation: ReactCompositeComponent.render(): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.

For Example :

var formComponent = React.createClass({
	render : function(){
		return (
			<input type="text" />
			<button>Submit</button>
		)
	}
});

Here i will return component without parent node. So it will assume undefined to the DOM.

We need some changes in the above script. Like below

var formComponent = React.createClass({
	render : function(){
		return (
			<div>
				<input type="text" />
				<button>Submit</button>
			</div>
		)
	}
});

without <div></div> you will get an error.

Leave a Reply

Your email address will not be published. Required fields are marked *