question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React.createElement: type is invalid

See original GitHub issue

Hi! Thank you for creating this plugin! I’m currently trying to implement it in my project, but I keep getting the following error: warning.js:33 Warning: React.createElement: 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. Check the render method of AddEditLinkModal.

Perhaps I’m implementing it the wrong way? I’m using webpack for my assets. I’ve put “react-image-crop” inside my “vendor” entry.

Inside my react component I’ve done the following import: import ReactCrop from "react-image-crop"; And the logic I created:

public state: State = {
	crop: {
		x: 0,
		y: 0,
		aspect: 10 / 4,
		width: 50,
	},
};
constructor(props: Props, state: State) {
	super(props, state);

	this.onCropImageChange = this.onCropImageChange.bind(this);
}

public handleImgSelection(e: any) {
	e.preventDefault();
	const {setImg} = this.props;

	const reader = new FileReader();
	const file = e.target.files[0];

	reader.onloadend = () => {
		setImg(file, reader.result);
	};

	reader.readAsDataURL(file);
}

public onCropImageChange(crop: State["crop"]) {
	this.setState({crop: crop});
}

Inside my render I’m rendering the following ReactCrop: <ReactCrop crop={this.state.crop} src={imgPreview} onChange={this.onCropImageChange} />

The imgPreview is the reader.result which is saved to my redux store.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
maxsizecommented, Nov 1, 2018

Hi guys, I have the same problem here, I am using ts in my project, after some research, I find that I have to do something like this to make it work: import * as ReactCrop from 'react-image-crop'; render() { const Component = (ReactCrop as any).default; return ( <Component src={src} ... /> ) } It seems like something is wrong in the definition file. help this helps.

0reactions
maxsizecommented, Nov 8, 2018

Hi @DominicTobias , I am using 6.0.4.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React.createElement: type is invalid -- expected a string
If you use react-router-config make sure you use the component property instead of render , because the package doesn't support the later.
Read more >
(React) Element type is invalid, expected a string (for built in ...
To solve the error "Element type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got",...
Read more >
React.createElement: type is invalid — expected a string
This somewhat cryptic error usually has a simple solution. More often than note a quick notation fix can solve the issue. What's the...
Read more >
Error React createElement type is invalid expected a string for ...
Error React createElement type is invalid expected a string for built-in components or a class function for composite components but got object.
Read more >
Warning: React.createElement: type is invalid -- expected a ...
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found