Skip to content

Instantly share code, notes, and snippets.

@Temzasse
Last active February 17, 2017 09:22
Show Gist options
  • Save Temzasse/dee9d30a8e3e174ff2254dc906367ce2 to your computer and use it in GitHub Desktop.
Save Temzasse/dee9d30a8e3e174ff2254dc906367ce2 to your computer and use it in GitHub Desktop.
React - "Cannot read property 'getNativeNode' of null" bug
// In GalleryItemContainer.js
componentWillMount() {
// some stuff here...
this.props.fetchGalleryItem(slug);
}
...
// In my sagas
function* fetchGalleryItem({ payload }) {
try {
const galleryItem = yield call(api.getGalleryItem, payload);
yield put(actions.receiveGalleryItem(galleryItem));
} catch (err) { // <--- error was swallowed here
yield put(actions.failGalleryItem());
}
}
...
// In GalleryItem.js component
renderGalleryImage(image, imageIdx) {
let url;
if (some_logic_here) {
url = 'something';
} else {
url = image.url.source_url; // <--- image.url was undefined here which caused the error
}
return (
<GalleryImage key={imageIdx}>
<GalleryImageInner
onClick={() => this.showLightBox(imageIdx)}
src={url}
/>
</GalleryImage>
);
}
render() {
return (
<GalleryImages>
{images.map((image, idx) => this.renderGalleryImage(image, idx)}
</GalleryImages>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment