Sometimes, we want to fix the ‘A valid React element (or null) must be returned’ error with one of the component error in React and JavaScript.
In this article, we’ll look at how to fix the ‘A valid React element (or null) must be returned’ error with one of the component error in React and JavaScript.
How to fix the ‘A valid React element (or null) must be returned’ error with one of the component error in React and JavaScript?
To fix the ‘A valid React element (or null) must be returned’ error with one of the component error in React and JavaScript, we should make sure our React component returns one root node or fragment.
For instance, we write:
import React from "react";
export default function App() {
return <div>hello world</div>;
}
to return one div.
Or:
import React from "react";
export default function App() {
return <>hello world</>;
}
to return a fragment.
Conclusion
To fix the ‘A valid React element (or null) must be returned’ error with one of the component error in React and JavaScript, we should make sure our React component returns one root node or fragment.