Installing Anchor
Learn how to install and set up Anchor, the revolutionary state management library for modern web applications.
Prerequisites
Before installing Anchor, ensure you have:
- A modern web browser for development
- A package manager like npm, yarn, or pnpm
Installation Options
Anchor provides multiple packages depending on your framework:
Core Package (Vanilla JavaScript/TypeScript)
Install the core package for framework-agnostic state management:
npm install @anchorlib/core
yarn add @anchorlib/core
pnpm add @anchorlib/core
bun add @anchorlib/core
React Integration
For React applications, install the React-specific package:
npm install @anchorlib/react
yarn add @anchorlib/react
pnpm add @anchorlib/react
bun add @anchorlib/react
Vue Integration
For Vue applications, install the Vue-specific package:
npm install @anchorlib/vue
yarn add @anchorlib/vue
pnpm add @anchorlib/vue
bun add @anchorlib/vue
Svelte Integration
For Svelte applications, install the Svelte-specific package:
npm install @anchorlib/svelte
yarn add @anchorlib/svelte
pnpm add @anchorlib/svelte
bun add @anchorlib/svelte
Basic Setup
After installation, you can start using Anchor in your project:
import { anchor } from '@anchorlib/core';
export const state = anchor({
count: 0,
name: 'My App',
});
console.log(state.count); // 0
state.count++;
import { useObserved } from '@anchorlib/react';
import { state } from '../index.js';
const Counter = () => {
const count = useObserved(() => state.count);
return (
<div>
<p>Count: {count}</p>
<button onClick={() => state.count++}>Increment</button>
</div>
);
};
<script setup>
import { observedRef } from '@anchorlib/vue';
import { state } from '../index.js';
const count = observedRef(() => state.count);
</script>
<template>
<div>
<p>Count: {{ count }}</p>
<button @click="state.count++">Increment</button>
</div>
</template>
<script>
import { observedRef } from '@anchorlib/svelte';
import { state } from '../index.js';
const count = observedRef(() => state.count);
</script>
<div>
<p>Count: {$count}</p>
<button onclick={() => state.count++}>Increment</button>
</div>
TypeScript Support
Anchor is written in TypeScript and provides first-class TypeScript support with comprehensive type definitions included in every package.
Next Steps
After installing Anchor, check out these guides to get started:
- Usage Guide - Learn how to use Anchor's core features
- Reactivity - Understand Anchor's fine-grained reactivity system
- Immutability - Learn about Anchor's true immutability approach
- Framework-specific guides:
Need Help?
If you're having trouble with installation: