Skip to content

Instantly share code, notes, and snippets.

View GGrassiant's full-sized avatar
:octocat:
Continuously learning

Guillaume Grassiant GGrassiant

:octocat:
Continuously learning
View GitHub Profile
@marekpiechut
marekpiechut / sublime-medium.js
Created July 3, 2020 11:59
Get lazy loading cheap with IntersectionObserver in React
const useLazyMediaLoad = media => {
const [url, setUrl] = useState<?string>(null)
const targetRef = useRef<?HTMLElement>(null)
useEffect(() => {
if (!IntersectionObserver) {
thumbLoader(media).then(setUrl)
} else if (targetRef.current) {
let observer = new IntersectionObserver(
entries =>
@dhh
dhh / pagination_controller.js
Last active January 11, 2026 06:01
HEY's Stimulus Pagination Controller
/*
ERB template chunk from The Feed's display of emails:
<section class="postings postings--feed-style" id="postings"
data-controller="pagination" data-pagination-root-margin-value="40px">
<%= render partial: "postings/snippet", collection: @page.records, as: :posting, cached: true %>
<%= link_to(spinner_tag, url_for(page: @page.next_param),
class: "pagination-link", data: { pagination_target: "nextPageLink", preload: @page.first? }) unless @page.last? %>
</section>