RepositoryTypeScriptPLPoland
ID

Idered/behavior-tree

🌲 Manage React state with Behavior Trees

119stars
3forks
6issues
1views

JavaScript/TypeScript implementation of Behavior Trees.

📕 Read the documentation to learn the API.

Gitter

Note: This software is in early development stage. It's not production ready. API may change.

Behavior Tree Toolkit

  • 🌲 @btree/core - Framework agnostic behavior trees implementation
  • ⚛ @btree/react - Hooks and docs how to use BT with React

Quick start

npm install @btree/core
import {nodes} from '@btree/core'

const initialState = {
  isLoggedIn: false
}

const AuthBehavior = nodes.root('Auth behavior', () =>
  /* Selector runs child one by one until one of them succeeds */
  nodes.selector([
    /* Sequence runs child one by one and stops if any child return failure status */
    nodes.sequence([
      /* Condition node run logic checks on current state */
      nodes.condition('Is logged in', (state, props) => state.isLoggedIn),
      /* Action node is used for side effects and state modifications */
      nodes.action('Redirect to dashboard', (state, props) => {
        navigate('/dashboard')
      }),
    ]),
    nodes.sequence([
      nodes.action('Redirect to login page', () => {
        navigate('/login')
      }),
    ]),
  ])
)

// Create instance of tree
const authTree = AuthBehavior(initialState)

// Run tree logic
authTree.tick()

// You can also run it with props
authTree.tick({authKey: 'xyz'})

Why?

Getting app features done is cool but what about future changes? As time passes, you will forgot how given feature works. Writing comments or docs is not something that developers have in mind all the time. This library will handle that for you.

With Behavior Tree notation all your code will be wrapped with nodes - that allows to visualize how it works. Check /packages/react/example for implementation of this logic.

Similar Projects

Discover other similar projects and AI models.

RepositoryTypeScript
pmndrs/zustand

🐻 Bear necessities for state management in React

59.0k
Nov 23, 2026
RepositoryTypeScript
diegohaz/constate

React Context + State

4.0k
Nov 28, 2026
RepositoryTypeScript
bluebill1049/little-state-machine

📠 React custom hook for persist state management

1.5k
Oct 25, 2026
RepositoryTypeScript
codetypess/behavior3-ts

behavior tree for ts/js

61
Nov 12, 2026
RepositoryTypeScript
freeCodeCamp/freeCodeCamp

freeCodeCamp.org's open-source codebase and curriculum. Learn math, programming, and computer science for free.

459.9k
Dec 2, 2026
RepositoryJavaScript
pruttned/owl-bt

owl-bt is editor for Behavior trees. It has been inspired by Unreal engine behavior trees in a way, that it supports special node items like decorators and services. This makes trees smaller and much more readable.

187
Dec 10, 2022
RepositoryC++
AutoAPMS/auto-apms

A versatile framework for developing robot behaviors using behavior trees in ROS 2.

110
Nov 17, 2026
RepositoryC#
MinaPecheux/UnityTutorials-BehaviourTrees

The code for a short tutorial on how to create a simple guard AI using behaviour trees in Unity/C# (in text or video format)!

108
Nov 2, 2021
RepositoryJavaScript
react/react

The library for web and native user interfaces.

253.0k
Nov 30, 2026