Skip to content

Instantly share code, notes, and snippets.

@onurkerimov
onurkerimov / example.js
Created January 4, 2021 19:27
Dark mode detection with MutationObserver API
const htmlTag = document.querySelector('html')
const checkDarkMode = () => htmlTag.hasAttribute('dark')
const watchDarkMode = (onChange) => {
let isDark, isDarkBefore
isDark = checkDarkMode()
onChange(isDark)
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
@onurkerimov
onurkerimov / Ideal mental model for React.md
Last active March 2, 2023 10:52
My take on an ideal mental model for React (A React without hooks)
import create from 'xoid'
import React from 'react'

const App = ($props, { effect, read }) => {
  const $count = create(0)
  const increment = () => $count.update(state => state + 1)

 // conditionally callable context reader