Check out example codes for "How to prevent anchor links from scrolling behind a sticky header with one line of CSS". It will help you in understanding the concepts better.

Code Example 1

// src/scss/navigation.scss

$sticky-breakpoint: 32em;

// 1. Approximate height of sticky navigation.
[id] {
  @media (min-height: $sticky-breakpoint) {
    scroll-margin-top: 100px; // 1
  }
}

.navigation {
  // ...

  @media (min-height: $sticky-breakpoint) {
    position: sticky;
    top: 0;
  }
}

Learn ReactJs, React Native from akashmittal.com