Uncaught Error: Must provide a ref to the DOM element to be observed. #4
Closed
Description
Amazing plugin and thanks for open-sourcing this! maybe im doing something wrong but im folowing the instructions and getting an error
Uncaught Error: Must provide a ref to the DOM element to be observed.
at Observed.observe (Observed.js:122)
at Observed.componentDidMount (Observed.js:83)
at commitLifeCycles (react-dom.development.js:8770)
at commitAllLifeCycles (react-dom.development.js:9946)
at HTMLUnknownElement.callCallback (react-dom.development.js:542)
at Object.invokeGuardedCallbackDev (react-dom.development.js:581)
at invokeGuardedCallback (react-dom.development.js:438)
at commitRoot (react-dom.development.js:10050)
at performWorkOnRoot (react-dom.development.js:11017)
at performWork (react-dom.development.js:10967)
this is the main container
import React from 'react';
import Observed from 'react-observed';
import 'intersection-observer';
// containers
import Introduction from './views/Introduction';
import FeaturedProjects from '../FeaturedProjects';
import MyInformation from '../MyInformation';
const Homepage = () => (
<main>
<Introduction />
<Observed
initialViewState
onChange={isInView => {}}
options={{
root: null,
rootMargin: '0px 0px -160px 0px',
threshold: [0, 0.25, 0.5, 0.75, 1]
}}
>
{({ isInView, mapRef }) => (
<FeaturedProjects isInView={isInView} mapRef={mapRef} />
)}
</Observed>
</main>
);
export default Homepage;
and this is the component wrapped in it, its a stateless pure function component
const FeaturedProjects = ({ isInView, mapRef }) => (
<section ref={mapRef} className="featured-projects">
{isInView ? (
<ProjectPreview
number="01"
project={projectTest}
link="/"
mainImage={mainImage}
/>
) : (
<span>not in view.</span>
)}
</section>
);
export default FeaturedProjects;
Also, do I need the ternary operator? can I leave it blank just to render it if in view? thanks again for the help in advance
Metadata
Assignees
Labels
No labels