React Alien Signals is a TypeScript library that provides hooks built on top of Alien Signals. It offers a seamless integration with React, ensuring concurrency-safe re-renders without tearing.
Click to expand
createSignalcreateComputedcreateEffect and manage multiple effects with createSignalScopeuseSignal, useSignalValue, and useSetSignal for seamless state managementInstall react-alien-signals and its peer dependency alien-signals via npm:
npm install react-alien-signals alien-signals
Create a writable signal and use it within your components:
import { createSignal, useSignal } from "react-alien-signals";
const count = createSignal(0);
function Counter() {
const [value, setValue] = useSignal(count);
return (
<button onClick={() => setValue(value + 1)}>
Count: {value}
</button>
);
}
Create derived state that automatically updates:
import { createSignal, createComputed, useSignalValue } from "react-alien-signals";
const count = createSignal(1);
const double = createComputed(() => count() * 2);
function Display() {
const doubleValue = useSignalValue(double);
return
Double: {doubleValue}
;
}
Run side effects in response to signal changes:
import { createSignal, createEffect, useSignalScope } from "react-alien-signals";
const count = createSignal(0);
function Logger() {
useSignalScope(() => {
createEffect(() => {
console.log('Count changed:', count());
});
});
return null;
}
React Alien Signals provides several hooks to interact with signals:
useSignal(signal): Returns [value, setValue] tuple for reading and writinguseSignalValue(signal): Returns the current value (read-only)useSetSignal(signal): Returns a setter function (write-only)useSignalEffect(effectFn): Runs a side effect based on signal changesuseSignalScope(callback): Manages effect scopes within a componentuseComputed(getter, deps): Creates and subscribes to a computed signaluseComputed(getter, deps)The useComputed hook expects a getter and a dependency array.
The dependency array is similar to a dependency array used in useMemo or useEffect
Here is an example
function Component({ a }) {
useComputed(
() => {
return a + mySignal();
},
[a, mySignal]
);
}
Contributions are welcome! Please read the Contributing Guidelines before getting started.
$ claude mcp add react-alien-signals \
-- python -m otcore.mcp_server <graph>