![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
@2toad/fluent-state
Advanced tools
A fluent JavaScript State Machine with full TypeScript support
A fluent JavaScript State Machine with full TypeScript support
Install package
npm i @2toad/fluent-state
import { fluentState } from '@2toad/fluent-state';
// or
const { fluentState } = require('@2toad/fluent-state');
fluentState
.from('vegetable').to('diced').or('pickled')
.from('diced').to('salad').or('trash');
fluentState
.when('diced').do(() => console.log('diced'));
fluentState.transition('diced');
// or
fluentState.next();
The current state
Adds a state
// Add the 'vegetable' state
fluentState.from('vegetable');
Adds a transition to a state
fluentState
.from('vegetable') // Add the 'vegetable' state
.to('diced'); // add the 'diced' state, with a transtion from 'vegetable'
Adds a transition to a state
fluentState
.from('vegetable') // Add the 'vegetable' state
.to('diced') // add the 'diced' state, with a transtion from 'vegetable'
.or('pickled') // add the 'pickled' state, with a transtion from 'vegetable'
.or('discarded'); // add the 'discarded' state, with a transtion from 'vegetable'
Explicitly set the state without triggering a transition
fluentState.setState('diced');
NOTE: the state is initially set to the first state you add via
from()
, and it is implicitly set when you transition to a new state viatransition()
ornext()
Returns true if the state exists
fluentState.has('vegetable');
Removes a state (and all of its transitions)
fluentState.remove('vegetable');
Removes all states
fluentState.clear();
true
upon success.// Transition to the 'diced' state
fluentState.transition('diced');
// Transition to the 'diced' or 'discarded' state (selected at random)
fluentState.transition('diced', 'discarded');
true
upon success.fluentState.next();
// A random state, excluding 'pickled' and 'discarded'
fluentState.next('pickled', 'discarded');
You can add callbacks to any state
Specifies the state you want to add a callback to
fluentState.when('diced');
Adds a callback
fluentState
.when('diced')
.do((previousState, fluentState) => {
console.log(`Transitioned from "${previousState.name}"`);
});
Adds another callback
fluentState
.when('diced')
.do(() => console.log('Transitioned to "diced"'))
.and((previousState, fluentState) => {
console.log(`Transitioned from "${previousState.name}"`);
});
And of course it's all chainable
fluentState
.when('diced').do(() => console.log('Transitioned to "diced"'))
.when('pickled').do(() => console.log('Transitioned to "pickled"'));
You can hook into the state machine lifecycle via the observe
method.
fluentState.observe(Lifecycle.BeforeTransition, (currentState, newState) => {
// You can prevent the transition by returning false from this event
return false;
});
// Chainable
fluentState
.observe(Lifecycle.FailedTransition, () => console.log('Transition failed'))
.observe(Lifecycle.FailedTransition, () => console.log('Multiple hooks allowed on each event'))
.observe(Lifecycle.AfterTransition, () => console.log('Transition complete'));
Order: BeforeTransition -> FailedTransition -> AfterTransition
BeforeTransition
(currentState: State, nextState: string): boolean
FailedTransition
(currentState: State, targetState: string): void
AfterTransition
(previousState: State, currentState: State): void
So you want to contribute to the Fluent State project? Fantastic! Please read the Contribute doc to get started.
FAQs
A fluent JavaScript State Machine with full TypeScript support
We found that @2toad/fluent-state demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.