Reputation: 689
https://codesandbox.io/s/sparkling-paper-mxb9g?file=/src/index.tsx
All my imports and exports are fine.
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check the render method of
Search
.
Search.tsx Render function
render = () => {
return (
<div className="wrapper">
<div className='content'>
<SearchBox placeholder="Search" underlined={true} onChange={this.setQuery} onSearch={this.searchQuery}/>
<this.RenderDomains />
<this.RenderImages />
</div>
</div>
)
}
How does this error relate to this block of code?
Upvotes: 3
Views: 4640
Reputation: 2638
The reasoning you're getting the error is because of how you're trying to render the domains and images in the render method of your Search component.
User defined components must start with an uppercase letter. So calling <this.RenderDomains />
isn't allowed. You have a couple options for fixing this.
<this.RenderDomains />
you should call the method and store the returned value in a variable and then render the variable or just directly return the results of the method. The example below shows both examples.render = () => {
const domains = this.RenderDomains();
const images = this.RenderImages();
return (
<div className="wrapper">
<div className='content'>
<SearchBox placeholder="Search" underlined={true} onChange={this.setQuery} onSearch={this.searchQuery}/>
{domains}
{this.renderImages()}
</div>
</div>
)
}
render = () => {
const RenderDomains = this.RenderDomains;
const RenderImages = this.RenderImages;
return (
<div className="wrapper">
<div className='content'>
<SearchBox placeholder="Search" underlined={true} onChange={this.setQuery} onSearch={this.searchQuery}/>
{<RenderDomains />}
{<RenderImages />}
</div>
</div>
)
}
Upvotes: 2