How to Install 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/coreyarn add @anchorlib/corepnpm add @anchorlib/corebun add @anchorlib/coreReact Integration
For React applications, install the React-specific package:
npm install @anchorlib/reactyarn add @anchorlib/reactpnpm add @anchorlib/reactbun add @anchorlib/reactSolidJS Integration
For SolidJS applications, install the SolidJS-specific package:
npm install @anchorlib/solidyarn add @anchorlib/solidpnpm add @anchorlib/solidbun add @anchorlib/solidSvelte Integration
For Svelte applications, install the Svelte-specific package:
npm install @anchorlib/svelteyarn add @anchorlib/sveltepnpm add @anchorlib/sveltebun add @anchorlib/svelteVue Integration
For Vue applications, install the Vue-specific package:
npm install @anchorlib/vueyarn add @anchorlib/vuepnpm add @anchorlib/vuebun add @anchorlib/vueBasic Setup
After installation, you can start using Anchor in your project:
import { mutable } from '@anchorlib/core';
// Create a shared, reactive state object.
export const state = mutable({
count: 0,
name: 'My App',
});import { template } from '@anchorlib/react';
import { state } from '../state.js';
export const Counter = template(() => (
<div>
<p>Count: {state.count}</p>
<button onClick={() => state.count++}>Increment</button>
</div>
));import { state } from '../state.js';
const Counter = () => {
return (
<div>
<p>Count: {state.count}</p>
<button onClick={() => state.count++}>Increment</button>
</div>
);
};<script>
import { state } from '../state.js';
</script>
<div>
<p>Count: {state.count}</p>
<button onclick={() => state.count++}>Increment</button>
</div><script setup>
import { observedRef } from '@anchorlib/vue';
import { state } from '../state.js';
// Observe the count value.
const count = observedRef(() => state.count);
</script>
<template>
<div>
<p>Count: {{ count }}</p>
<button @click="state.count++">Increment</button>
</div>
</template>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:
- Configuration Guide - Learn how to configure Anchor
- Reactivity - Understand Anchor's fine-grained reactivity system
- Immutability - Learn about Anchor's true immutability approach
- Data Integrity - Learn about Anchor's Data Integrity
- Framework-specific guides:
Need Help?
If you're having trouble with installation: