Self-review: Implementing scroller position with render props - Advanced React

Self-review: Implementing scroller position with render props - Advanced React

Sep 16, 2024ยท

1 min read

  1. Considering the MousePosition component receives a prop called render, which is a function, what are valid options of JSX returned from the component?

    •   return render(<div>{mousePosition}</div>);
      
    •   return (
          <div>
            render({mousePosition})
          </div>
        );
      
    •   return render({ mousePosition });
      
  2. The PointMouseLogger component returns the below JSX.

     <p>
      ({mousePosition.x}, {mousePosition.y})
     </p>
    

    After incorporating the MousePosition component as part of the JSX returned by PointMouseLogger, what should be the new JSX that PointMouseLogger returns?

    •   return(
          <MousePosition>
            {({ mousePosition }) => (
              <p>
                ({mousePosition.x}, {mousePosition.y})
              </p>
            )}
          </MousePosition>
        );
      
    •   return(
          <MousePosition>
            {({ mousePosition }) => (
              <p>
                ({mousePosition.x}, {mousePosition.y})
              </p>
            )}
          </MousePosition>
        );
      
    •   return(
          <MousePosition
            render={({ mousePosition }) => (
              <p>
                ({mousePosition.x}, {mousePosition.y})
              </p>
            )}
          />
        );
      
  3. The App component initially presents the below output structure

     function App() {
       return(
         <div className="App">
           <header className="Header">Little Lemon Restaurant ๐Ÿ•</header>
           <PanelMouseLogger />
           <PointMouseLogger />
         </div>
       );
     }
    

    After adding the MousePosition component into the mix, would you still have to perform any changes to the App component?

    • Yes

    • No