I'm working on an older version of React and the version is 15.4. This version doesn't support createRef()
I've code which works for React 16.8 or later but doesn't work for this version. getting an error which is
c.default.createRef is not a function
Here's my code whihc works for React 16.8 or later version
import React, { Component } from 'react';
const TrustBox = ({ trustBoxRef }) => (
<div ref={trustBoxRef} className="trustpilot-widget">
<a href="https://www.trustpilot.com/review/example.com" target="_blank" rel="noopener noreferrer">
Trustpilot
</a>
</div>
);
class TrustBoxContainer extends Component {
constructor(props) {
super(props);
this.trustBoxRef = React.createRef();
}
componentDidMount() {
if (window.Trustpilot) {
window.Trustpilot.loadFromElement(this.trustBoxRef.current, true);
}
}
render() {
return <TrustBox trustBoxRef={this.trustBoxRef} />;
}
}
export default TrustBoxContainer;
I did a lot of research on how to get the older version to work but in vain. Can someone please help me ?
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment