I have these refs in my constructor
constructor(props) {
super(props);
//All Refs
this.sunglassesTintsTab = React.createRef();
this.gradientTintsTab = React.createRef();
this.fashionTintsTab = React.createRef();
this.lensTintStandardSwatchesContainer = React.createRef();
this.lensTintMirrorSwatchesContainer = React.createRef();
}
And this is my componentDidMount
componentDidMount() {
console.log('ComponentDidMount Start');
if (this.state.modalType === 'lensTintsBlokz') {
this.getLensTintSwatches('blokz');
} else {
this.setState({ lensTintsTabsContainerHidden: false });
this.getLensTintSwatches('sunglasses');
}
}
In the getLensTintSwatches function - this is being called in componentDidMount
this.lensTintStandardSwatchesContainer.current.innerHTML = '';
this.lensTintMirrorSwatchesContainer.current.innerHTML = '';
I'm getting the following error.
Uncaught TypeError: Cannot set property 'innerHTML' of null
I have tried both the standard React.createRef() and callback style ref but the current value of all the refs is returning null. What am I doing wrong here?
UPDATE: I'm passing
ref={this.xyxRef}
as prop in the respective elements.Another observation- The console.log in componentDidMount is not triggered, based on other console errors
This is the flow:
Constructor -> Render -> Constructor -> Render -> This ERROR