Skip to content

React 16 createRef crash #344

@neutraali

Description

@neutraali

Turns out if a component has any refs created with React 16+ the lib crashes. For example, trying to react-element-to-jsx-string the following component:

class Example extends React.Component {
	constructor(props) {
		super(props);
		this._ref = React.createRef();
	}
	render() {
		return <div ref={this._ref} />;
	}
}

... Will result in the following crash:

Uncaught RangeError: Maximum call stack size exceeded
    at Array.reduce (<anonymous>)
    at sortObject (index.js:225)
    at eval (index.js:230)
    ...

A (hopefully) temporary fix is to filter out said props, but I don't think this is ideal.

this.reactElementToJSXString(item, {
	filterProps: ['ref', 'key']
	...
});

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions