1. Scroll to section task

by Vitalii_N

HTML

<div id="app"></div>

CSS

.container {
  width: 300px;
}

h2 {
  margin-top: 16px;
  font-weight: 700;
  font-size: 22px;
}

h1 {
  margin-bottom: 20px;
  font-size: 32px;
  font-weight: 700;
}

.menu {
  position: fixed;
   left: 350px;
   top: 20px;
   border-radius: 6px;
   border: 2px solid green;
   padding: 16px;
   display: flex;
   flex-direction: column;
   gap: 16px;
}

React

// Your task is to implement scroll to section for buttons in the menu
// Clicking on it should scroll your page to particular section
// Section 1 using anchors as a solution, but your task is to make it without anchoring

const {createRoot} = ReactDOM;
const {useEffect, useState, useRef} = React;

const sections = [
	{ id: 'section1', name: 'Section 1', content: `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.` },
  { id: 'section2', name: 'Section 2', content: `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.` },
  { id: 'section3', name: 'Section 3', content: `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was...