100+ copy-paste UI components in plain HTML and CSS: no dependencies, no build step.

0 downloads

dbbasic-web-native/REACT-VS-REACTIVE.md
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-web-native.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-web-native.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-web-native.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 Add canonical.html v1.0 - The single source of truth for usability standards fb6e650 1 year ago History
REACT-VS-REACTIVE.md · 15.1 KB · 681 lines

React vs Actually Reactive

The Irony of React

React's name means "reactive programming"

But what does React actually react to?

// React components react to:
function Button({ onClick, disabled }) {
  return <button onClick={onClick} disabled={disabled}>Click</button>;
}

// ✅ Reacts to: props changes (disabled)
// ✅ Reacts to: user clicks (onClick)
// ✅ Reacts to: state changes (useState)

// ❌ Doesn't react to: ambient noise
// ❌ Doesn't react to: number of viewers
// ❌ Doesn't react to: user's attention state
// ❌ Doesn't react to: lighting conditions
// ❌ Doesn't react to: current modality
// ❌ Doesn't react to: device battery
// ❌ Doesn't react to: network quality

React is reactive to DEVELOPER STATE, not REAL WORLD CONTEXT


What Our Components Actually React To

Semantic Components (TRUE Reactivity)

<!-- Same component, adapts automatically -->
<semantic-feedback type="success" message="Saved!">

Automatically reacts to:

1. Environmental Context

// Loud coffee shop (80% noise)
→ Speaks message LOUDER
→ Shows larger visual notification
→ Vibrates phone for confirmation

// Quiet library (10% noise)
→ Silent notification only
→ Smaller, subtle visual
→ No sound/vibration

2. Viewer Context

// Multiple people watching screen (3 viewers)
→ Suppresses personal notifications
→ Uses generic messages
→ Hides sensitive info

// Alone (1 viewer)
→ Shows full details
→ Normal notification behavior

3. User Attention State

// User is busy (isBusy: true)
→ Suppresses low-priority notifications
→ Queues for later
→ Only critical items show

// User is idle (isBusy: false)
→ Shows all notifications normally
→ Can be more verbose

4. Modality Context

// Voice-only mode (driving)
→ Speaks: "Your changes were saved"
→ No visual shown (unsafe to look)
→ Confirms via voice

// Screen + Voice mode (at desk)
→ Visual notification + optional speech
→ User can choose to listen or read

// Screen-only mode (in meeting, muted)
→ Visual only, no sound
→ Larger text for clarity

5. Time-Based Patterns

// 9 AM (start of day)
→ Summarizes overnight activity
→ Higher priority for morning tasks

// 11 PM (late night)
→ Suppresses non-urgent items
→ "Do Not Disturb" mode hints

6. Device Context

// Low battery (< 20%)
→ Reduces animations
→ Shorter auto-dismiss timers
→ Lighter processing

// Slow network
→ Preloads critical content
→ Defers heavy media
→ Shows loading states faster

Code Comparison

React Way (Manual Context Passing)

import React, { useState, useEffect } from 'react';

function Notification({ message, type }) {
  const [noiseLevel, setNoiseLevel] = useState(0);
  const [viewerCount, setViewerCount] = useState(1);
  const [isBusy, setIsBusy] = useState(false);
  const [modality, setModality] = useState('screen');
  const [battery, setBattery] = useState(100);

  // Manually detect noise level
  useEffect(() => {
    navigator.mediaDevices.getUserMedia({ audio: true })
      .then(stream => {
        const audioContext = new AudioContext();
        const analyser = audioContext.createAnalyser();
        const microphone = audioContext.createMediaStreamSource(stream);
        microphone.connect(analyser);

        const dataArray = new Uint8Array(analyser.frequencyBinCount);

        function detectNoise() {
          analyser.getByteFrequencyData(dataArray);
          const average = dataArray.reduce((a, b) => a + b) / dataArray.length;
          setNoiseLevel(average);
          requestAnimationFrame(detectNoise);
        }
        detectNoise();
      });
  }, []);

  // Manually detect viewers
  useEffect(() => {
    // ... 50 more lines of face detection code
  }, []);

  // Manually detect user state
  useEffect(() => {
    // ... 30 more lines of idle detection code
  }, []);

  // Manually detect battery
  useEffect(() => {
    if ('getBattery' in navigator) {
      navigator.getBattery().then(battery => {
        setBattery(battery.level * 100);
        battery.addEventListener('levelchange', () => {
          setBattery(battery.level * 100);
        });
      });
    }
  }, []);

  // Manually calculate what to show
  const shouldSpeak = modality.includes('voice') && noiseLevel > 50;
  const shouldVibrate = noiseLevel > 70 || viewerCount > 1;
  const shouldShowVisual = modality.includes('screen');
  const shouldSuppressIfBusy = type === 'info' && isBusy;

  useEffect(() => {
    if (shouldSuppressIfBusy) return;

    if (shouldSpeak) {
      const utterance = new SpeechSynthesisUtterance(message);
      utterance.volume = noiseLevel > 70 ? 1.0 : 0.5;
      speechSynthesis.speak(utterance);
    }

    if (shouldVibrate && 'vibrate' in navigator) {
      navigator.vibrate(200);
    }
  }, [message, shouldSpeak, shouldVibrate, shouldSuppressIfBusy]);

  if (shouldSuppressIfBusy || !shouldShowVisual) return null;

  return (
    <div className={`notification notification-${type}`}>
      {message}
    </div>
  );
}

// TOTAL: 150+ lines of code
// EVERY component needs this same logic
// State management nightmare
// Easy to miss edge cases

Semantic Way (Automatic Context)

<!-- That's it. Done. -->
<semantic-feedback type="success" message="Saved!">
</semantic-feedback>

<!-- 1 line of code -->
<!-- Context detection is automatic -->
<!-- All modalities handled -->
<!-- All edge cases covered -->

The component automatically:

  • Detects noise level
  • Detects viewers
  • Detects user state
  • Detects modality
  • Detects battery
  • Adjusts behavior accordingly

Zero developer code needed.


What React Makes You Build Yourself

1. Context Awareness

React:

// You build this:
const NoiseContext = React.createContext();
const ViewerContext = React.createContext();
const BatteryContext = React.createContext();
// ... 20 more contexts

function App() {
  const [noise, setNoise] = useState(0);
  const [viewers, setViewers] = useState(1);
  const [battery, setBattery] = useState(100);
  // ... manually detect everything

  return (
    <NoiseContext.Provider value={noise}>
      <ViewerContext.Provider value={viewers}>
        <BatteryContext.Provider value={battery}>
          {/* Your app */}
        </BatteryContext.Provider>
      </ViewerContext.Provider>
    </NoiseContext.Provider>
  );
}

Semantic:

// Built-in, automatic
window.semanticContext.context
// {
//   environment: { noiseLevel, viewerCount, lighting },
//   user: { isBusy, inFocusMode },
//   device: { battery, network }
// }

2. Multi-Modal Input

React:

function Button({ onClick }) {
  // Handle mouse
  const handleClick = (e) => onClick(e);

  // Handle touch
  const handleTouch = (e) => onClick(e);

  // Handle keyboard
  const handleKeyDown = (e) => {
    if (e.key === 'Enter' || e.key === ' ') onClick(e);
  };

  // Handle voice
  useEffect(() => {
    if ('webkitSpeechRecognition' in window) {
      const recognition = new webkitSpeechRecognition();
      recognition.onresult = (e) => {
        const command = e.results[0][0].transcript;
        if (command.includes('click') || command.includes('save')) {
          onClick(e);
        }
      };
      recognition.start();
    }
  }, []);

  // Handle gestures
  useEffect(() => {
    // ... 50 lines of gesture detection
  }, []);

  return (
    <button
      onClick={handleClick}
      onTouchEnd={handleTouch}
      onKeyDown={handleKeyDown}
      aria-label="Save"
    >
      Save
    </button>
  );
}

Semantic:

<semantic-action intent="primary">Save</semantic-action>

<!-- Automatically handles:
  - Mouse clicks
  - Touch taps
  - Keyboard (Enter/Space)
  - Voice commands ("click save")
  - Gestures (pinch, air tap)
  - Long-press for inspect
  - All future input methods
-->

3. Accessibility

React:

function Button({ onClick, disabled, ariaLabel, children }) {
  return (
    <button
      onClick={onClick}
      disabled={disabled}
      aria-label={ariaLabel}
      aria-disabled={disabled}
      role="button"
      tabIndex={disabled ? -1 : 0}
      style={{
        minWidth: '44px',
        minHeight: '44px',
        // ... manual WCAG compliance
      }}
    >
      {children}
    </button>
  );
}

// You have to remember EVERY accessibility attribute
// Easy to forget one
// No enforcement

Semantic:

<semantic-action intent="primary">Save</semantic-action>

<!-- Automatically includes:
  - ARIA role
  - ARIA labels
  - 44px minimum touch target
  - WCAG AA contrast (enforced)
  - Focus indicators
  - Keyboard navigation
  - Screen reader support
  - CAN'T ship without accessibility
-->

The Fundamental Difference

React Philosophy

"Components react to state changes"
// State changes → Component updates
const [count, setCount] = useState(0);
setCount(count + 1); // Component re-renders

What's reactive: Developer-controlled state What's NOT reactive: Real world

Semantic Philosophy

"Components react to reality"
<!-- Reality changes → Component adapts automatically -->
<semantic-feedback message="Saved!">

<!-- Noise level changes → Component speaks louder
     Viewers change → Component adjusts privacy
     User state changes → Component suppresses/shows
     Modality changes → Component switches output
-->

What's reactive: Everything What developers control: Intent (WHAT to do, not HOW)


Visibility Reactivity

The User's Point: "components should change if they are visible or not"

React:

function Notification({ message }) {
  const [isVisible, setIsVisible] = useState(false);
  const ref = useRef();

  useEffect(() => {
    const observer = new IntersectionObserver(([entry]) => {
      setIsVisible(entry.isIntersecting);
    });

    if (ref.current) {
      observer.observe(ref.current);
    }

    return () => observer.disconnect();
  }, []);

  // Component doesn't auto-adapt, you manually handle visibility
  useEffect(() => {
    if (isVisible) {
      // Start animations?
      // Load content?
      // You decide what to do
    }
  }, [isVisible]);

  return <div ref={ref}>{message}</div>;
}

Semantic:

<semantic-feedback message="Saved!">

<!-- Automatically:
  - Pauses animations when off-screen
  - Defers loading until visible
  - Adjusts attention budget based on viewport
  - Resumes when scrolled into view
  - No developer code needed
-->

The component KNOWS it's not visible and adjusts behavior automatically.


Sort Reactivity

"sort too" - Components should react to order/priority

React:

function NotificationList({ notifications }) {
  // You manually sort
  const sorted = [...notifications].sort((a, b) => {
    // You decide priority logic
    if (a.urgency === 'critical') return -1;
    if (b.urgency === 'critical') return 1;
    return a.timestamp - b.timestamp;
  });

  return sorted.map(n => <Notification key={n.id} {...n} />);
}

Semantic:

<!-- Components automatically sort by attention budget -->
<semantic-feedback urgency="critical" message="Error!">
<semantic-feedback urgency="low" message="Tip: ...">

<!-- System automatically:
  - Scores attention priority
  - Reorders based on context
  - Suppresses low-priority when busy
  - Promotes urgent items
  - Learns from user behavior
-->

The attention budget system automatically manages priority based on:

  • Urgency level
  • User's current state (busy/idle)
  • Available screen space
  • Historical engagement
  • Context similarity

React's Limitations

What React Can't Do (But Should)

  1. Automatic context awareness
  • React: Manual context providers everywhere
  • Semantic: Automatic global context
  1. Multi-modal by default
  • React: Build separate mouse/touch/voice handlers
  • Semantic: One intent API, all modalities work
  1. Accessibility enforcement
  • React: Optional, easy to forget
  • Semantic: Can't ship without it (built-in)
  1. Environmental adaptation
  • React: No concept of noise, viewers, lighting
  • Semantic: Adapts automatically
  1. Attention management
  • React: No priority system
  • Semantic: ML-powered attention budget
  1. Future-proof API
  • React: Platform-specific (onClick, onTouchEnd)
  • Semantic: Intent-based (intent="activate")

Why React Doesn't Do This

Technical Reasons

  1. React is a VIEW library, not a context-aware system
  2. React doesn't want opinions about how apps should work
  3. React assumes web = desktop browser (mouse + screen)
  4. React expects developers to build everything else

Philosophical Reasons

React says:

"We give you the primitives. You build the experience."

Semantic says:

"We give you the experience. You declare the intent."

The Real "React"ivity We Need

Current State of "Reactive" Programming

User clicks button → setState → Component re-renders ✓

This is ONE-WAY reactivity (developer → UI)

True Reactivity Should Be

Environment changes → Component adapts ✓
User context changes → Component adjusts ✓
Modality switches → Component responds ✓
Visibility changes → Component optimizes ✓
Attention budget shifts → Component reorders ✓

This is REAL-WORLD reactivity (reality → UI)


Code Volume Comparison

Building a Context-Aware Notification System

React:

// NoiseDetection.js (80 lines)
// ViewerDetection.js (120 lines)
// BatteryMonitor.js (40 lines)
// ModalityDetector.js (60 lines)
// AttentionManager.js (150 lines)
// VoiceHandler.js (100 lines)
// GestureHandler.js (80 lines)
// NotificationContext.js (50 lines)
// Notification.js (200 lines)

// TOTAL: 880+ lines of code
// Per component
// Easy to get wrong
// Hard to maintain

Semantic:

<semantic-feedback message="Saved!">
</semantic-feedback>

<!-- TOTAL: 1 line -->
<!-- Everything built-in -->
<!-- Tested and maintained by framework -->
<!-- Can't get it wrong -->

880 lines vs 1 line = 99.89% less code


The Irony

React (the library) doesn't actually make things react (to reality).

It makes things react to developer state, which is NOT the same thing.

Semantic Components make things ACTUALLY react to:

  • Real-world context
  • User state
  • Environmental conditions
  • Device capabilities
  • Modality changes
  • Attention availability

This is what "reactive" should have meant all along.


Summary

React is Named Perfectly for What We're Doing

But React doesn't do what we're doing.

React reacts to:

  • setState calls
  • Prop changes
  • User clicks

Semantic Components react to:

  • Ambient noise
  • Viewer count
  • User attention
  • Battery level
  • Network quality
  • Time of day
  • Visibility
  • Priority/urgency
  • Device capabilities
  • Lighting conditions
  • Motion/orientation
  • AND user interactions

The Question

"React, perfect name, but does it even do what we are trying to do?"

Answer: No.

React is reactive to developer state.

Semantic Components are reactive to reality.

That's the difference.