โ† Back to Home

๐ŸŽฏ Basic Signal - Get Started in 30 Seconds

Learn how to create and update reactive state with just one hook. No Redux, no Context, no complexity.

โ“

What is a Signal?

A signal is like a smart variable that automatically tells your UI when it changes. It's the simplest way to manage state in React!

๐ŸŽฏ Think of it like this: A regular variable is silent when it changes. A signal shouts "Hey, I changed!" and React automatically updates your UI.

๐Ÿค” createSignal vs useSignal - What's the Difference?

๐Ÿ“ฆ createSignal()

Creates a standalone signal outside components

// Outside component
const count = createSignal(0);

// Use anywhere!
function Display() {
  const value = useSignalValue(count);
  return <div>{value}</div>;
}

โœ… Use for global state shared across components

โš›๏ธ useSignal()

React hook - creates signal inside component

// Inside component
function Counter() {
  const [count, setCount] = useSignal(0);
  
  return (
    <button onClick={() => setCount(count + 1)}>
      {count}
    </button>
  );
}

โœ… Use for local state (like useState but reactive!)

๐Ÿ’ก In this demo: We use useSignal(0) because the counter is local to this component. For global state (like shopping cart), use createSignal()!

๐Ÿ’ก

Why Use Signals?

Because they make state management ridiculously simple!

โŒ Without Signals (Regular useState)

  • โ€ข Need Context for global state
  • โ€ข Props drilling everywhere
  • โ€ข Complex state management
  • โ€ข Lots of boilerplate code

โœ… With Signals

  • โ€ข Works anywhere instantly
  • โ€ข No props drilling needed
  • โ€ข Simple & straightforward
  • โ€ข Just one line of code!
๐Ÿš€

How To Use It? (3 Super Easy Steps!)

1

Create the signal

const [count, setCount] = useSignal(0);
//     โ†‘       โ†‘              โ†‘
//   value  updater    starting value
2

Display it in your UI

<div>{count}</div>  // Just use it like a regular variable!
3

Update it when needed

setCount(count + 1)  // UI updates automatically! โœจ

๐ŸŽ‰ That's it! You're now using reactive state! Try it below โฌ‡๏ธ

0

๐Ÿ‘† Try the buttons below!

๐Ÿ”ง

What Problems Does This Solve?

๐Ÿ˜ฐ Traditional React Problems

  • โŒProps Drilling: Passing state through 5+ components
  • โŒContext Hell: Multiple providers wrapping your app
  • โŒComplex Setup: Redux with actions, reducers, types...
  • โŒBoilerplate Code: 50+ lines for a simple counter

๐Ÿ˜Š SignalForge Solutions

  • โœ…No Drilling: Access state anywhere, anytime
  • โœ…No Providers: Zero setup, works immediately
  • โœ…Simple: If you know useState, you know signals
  • โœ…Minimal Code: 3 lines for the same counter!
๐ŸŒ

Real-World Example: Shopping Cart

Imagine you need a shopping cart quantity that multiple components can see and update:

๐Ÿ“ Create once (anywhere)

// cart.js
export const cartCount = 
  createSignal(0);

๐ŸŽฏ Use anywhere

// Header.jsx
const count = 
  useSignalValue(cartCount);
return <Badge>{count}</Badge>;

โž• Update anywhere

// ProductCard.jsx
cartCount.set(
  cartCount.get() + 1
);

โœจ Auto-updates!

// All components using 
// cartCount update 
// automatically! ๐ŸŽ‰

๐Ÿš€ Complete Code Example

Step 1: Import the hook
import { useSignal } from 'signalforge/react';
Step 2: Create your signal
const [count, setCount] = useSignal(0); // Start at 0
Step 3: Use it like normal state!
{count} // Display the value
setCount(count + 1) // Update it

๐Ÿ’ป Complete Code Example

import { useSignal } from 'signalforge/react';

function Counter() {
  // Create a signal with initial value 0
  const [count, setCount] = useSignal(0);

  return (
    <div>
      <h1>Count: {count}</h1>
      
      {/* Update the signal */}
      <button onClick={() => setCount(count + 1)}>
        Increment
      </button>
      
      <button onClick={() => setCount(0)}>
        Reset
      </button>
    </div>
  );
}

// That's it! Your component will automatically
// re-render when count changes. No useEffect,
// no useCallback, no useMemo needed!

๐Ÿ’ก Why SignalForge is Better

โŒ Traditional useState:
  • โ€ข Causes full component re-render
  • โ€ข Slow with many state updates
  • โ€ข Need useCallback/useMemo
  • โ€ข Complex prop drilling
โœ… SignalForge useSignal:
  • โ€ข Only re-renders what changed
  • โ€ข 33x faster with batching
  • โ€ข No extra optimization needed
  • โ€ข Global state built-in

๐ŸŽ“ Next Steps

Now that you understand basic signals, try these demos:

๐ŸŽฎ Interactive Playground (Click to expand)